Skip to content

Commit

Permalink
Merge pull request #113 from bearsunday/update-ci-setting
Browse files Browse the repository at this point in the history
Update QA
  • Loading branch information
koriym authored May 5, 2021
2 parents 233db21 + 11db031 commit e591814
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 130 deletions.
24 changes: 0 additions & 24 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,6 @@ jobs:
- name: Run PHPStan
run: ./vendor/bin/phpstan analyse -c phpstan.neon --no-progress --no-interaction --error-format=checkstyle | cs2pr

static-analysis-psalm:
name: Static Analysis with Psalm
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
tools: cs2pr
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Install dependencies
run: composer install --no-interaction --no-progress --prefer-dist

- name: Run Psalm
run: ./vendor/bin/psalm --show-info=false --output-format=checkstyle --shepherd | cs2pr

static-analysis-phpmd:
name: Static Analysis with PHPMD
runs-on: ubuntu-latest
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
},
"scripts-descriptions": {
"setup": "Setup the project",
"compile": "Compile scripts for the production. See http://bearsunday.github.io/manuals/1.0/en/production.html",
"compile": "Compile scripts for the production",
"test": "Run unit tests",
"tests": "Run tests and quality checks",
"coverage": "Generate test coverage report",
Expand All @@ -61,6 +61,7 @@
"cs-fix": "Fix the coding standard",
"sa": "Run static analysis",
"metrics": "Build metrics report",
"clean": "Clear cache files",
"serve": "Start built-in server",
"app": "Request app resource",
"page": "Request page resource"
Expand Down
23 changes: 10 additions & 13 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<ruleset
name="BEAR.Skeleton"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd"
xsi:noNamespaceSchemaLocation="vendor-bin/tools/vendor/squizlabs/php_codesniffer/phpcs.xsd"
>
<description>BEAR.Skeleton Coding Standard</description>
<arg name="basepath" value="."/>
Expand All @@ -28,24 +28,21 @@
<rule ref="Doctrine">
<!-- Inapplicable for this project -->
<exclude name="Generic.Formatting.MultipleStatementAlignment.NotSame"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming"/>
<exclude name="Squiz.Strings.DoubleQuoteUsage.ContainsVar"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming.SuperfluousPrefix"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming.SuperfluousSuffix"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming.SuperfluousSuffix"/>
<exclude name="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.MissingVariable"/>
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint"/>
<!-- PHP8 Attribute -->
<exclude name="PSR12.Files.FileHeader.IncorrectOrder"/>
<exclude name="PSR12.Files.FileHeader.SpacingAfterBlock"/>
<exclude name="SlevomatCodingStandard.PHP.RequireExplicitAssertion.RequiredExplicitAssertion"/>
<exclude name="Squiz.WhiteSpace.FunctionSpacing.Before"/>
<!-- Exclude files -->
<exclude-pattern>*/tests/Fake/*</exclude-pattern>
<exclude-pattern>*/tmp/*</exclude-pattern>
</rule>

<!-- Additional Rules -->
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
<properties>
<property name="searchAnnotations" value="true"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Commenting.DocCommentSpacing">
<properties>
<property name="annotationsGroups" type="array">
Expand Down
43 changes: 14 additions & 29 deletions phpmd.xml
Original file line number Diff line number Diff line change
@@ -1,38 +1,23 @@
<ruleset
name="PHPMD rule sets"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<!--codesize-->
<rule ref="rulesets/codesize.xml/CyclomaticComplexity">
<properties>
<property name="reportLevel" description="The Cyclomatic Complexity reporting threshold" value="10"/>
</properties>
</rule>
<rule ref="rulesets/codesize.xml/NPathComplexity" />
<rule ref="rulesets/codesize.xml/ExcessiveClassComplexity"/>
<rule ref="rulesets/codesize.xml/ExcessiveClassLength"/>
<rule ref="rulesets/codesize.xml/ExcessiveMethodLength"/>
<rule ref="rulesets/codesize.xml/ExcessiveParameterList"/>
<rule ref="rulesets/codesize.xml/ExcessivePublicCount"/>
<rule ref="rulesets/codesize.xml/TooManyFields"/>
<rule ref="rulesets/codesize.xml/TooManyMethods"/>
<description>PHPMD rule sets</description>

<!-- clean code -->
<rule ref="rulesets/cleancode.xml" externalInfoUrl="https://phpmd.org/rules/cleancode.html"/>
<!-- codesize -->
<rule ref="rulesets/codesize.xml" externalInfoUrl="https://phpmd.org/rules/codesize.html"/>
<!--controversial -->
<rule ref="rulesets/controversial.xml" externalInfoUrl="https://phpmd.org/rules/controversial.html"/>
<!--design-->
<rule ref="rulesets/design.xml/NumberOfChildren"/>
<rule ref="rulesets/design.xml/DepthOfInheritance"/>
<rule ref="rulesets/design.xml/CouplingBetweenObjects" />
<rule ref="rulesets/design.xml/CountInLoopExpression" />
<rule ref="rulesets/design.xml" externalInfoUrl="https://phpmd.org/rules/design.html"/>
<!--naming-->
<rule ref="rulesets/naming.xml/ConstantNamingConventions"/>
<rule ref="rulesets/naming.xml/BooleanGetMethodName"/>
<rule ref="rulesets/naming.xml" externalInfoUrl="https://phpmd.org/rules/naming.html">
<exclude name="ShortVariable"/>
</rule>
<!--unusedcode-->
<rule ref="rulesets/unusedcode.xml/UnusedFormalParameter"/>
<rule ref="rulesets/unusedcode.xml/UnusedLocalVariable"/>
<rule ref="rulesets/unusedcode.xml/UnusedPrivateField"/>
<rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod"/>
<!--cleancode-->
<rule ref="rulesets/cleancode.xml/BooleanArgumentFlag"/>
<rule ref="rulesets/cleancode.xml/ElseExpression" />
<rule ref="rulesets/cleancode.xml/IfStatementAssignment" />
<rule ref="rulesets/cleancode.xml/DuplicatedArrayKey" />
<rule ref="rulesets/unusedcode.xml" externalInfoUrl="https://phpmd.org/rules/unusedcode.html"/>
</ruleset>
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: max
level: 6
paths:
- src
- tests
8 changes: 4 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="vendor/autoload.php">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd" bootstrap="vendor/autoload.php">
<coverage includeUncoveredFiles="false" processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
Expand All @@ -10,13 +10,13 @@
</coverage>
<testsuites>
<testsuite name="resource">
<directory suffix="Test.php">tests/Resource</directory>
<directory>tests/Resource</directory>
</testsuite>
<testsuite name="hypermedia">
<directory suffix="Test.php">tests/Hypermedia</directory>
<directory>tests/Hypermedia</directory>
</testsuite>
<testsuite name="http">
<directory suffix="Test.php">tests/Http</directory>
<directory>tests/Http</directory>
</testsuite>
</testsuites>
</phpunit>
12 changes: 10 additions & 2 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
xsi:schemaLocation="https://getpsalm.org/schema/config vendor-bin/tools/vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<directory name="src"/>
<directory name="tests"/>
<ignoreFiles>
<directory name="vendor" />
<directory name="vendor"/>
</ignoreFiles>
</projectFiles>
<!-- suppress -->
Expand All @@ -23,5 +24,12 @@
<directory name="src/Resource"/>
</errorLevel>
</NonInvariantDocblockPropertyType>
<PropertyNotSetInConstructor>
<errorLevel type="suppress">
<directory name="src/Resource"/>
</errorLevel>
</PropertyNotSetInConstructor>
</issueHandlers>
<plugins><pluginClass class="Psalm\PhpUnitPlugin\Plugin"/></plugins></psalm>
</issueHandlers>
</psalm>
7 changes: 4 additions & 3 deletions src/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
namespace BEAR\Skeleton;

use BEAR\Resource\ResourceObject;
use BEAR\Skeleton\Module\App;
use BEAR\Sunday\Extension\Application\AppInterface;
use BEAR\Sunday\Extension\Router\RouterInterface;
use BEAR\Skeleton\Module\App;
use Throwable;

use function assert;

/**
* @psalm-import-type Globals from \BEAR\Sunday\Extension\Router\RouterInterface
* @psalm-import-type Server from \BEAR\Sunday\Extension\Router\RouterInterface
* @psalm-import-type Globals from RouterInterface
* @psalm-import-type Server from RouterInterface
*/
final class Bootstrap
{
Expand Down
3 changes: 3 additions & 0 deletions src/Injector.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ private function __construct()
{
}

/**
* @SuppressWarnings(PHPMD.StaticAccess)
*/
public static function getInstance(string $context): InjectorInterface
{
return PackageInjector::getInstance(__NAMESPACE__, $context, dirname(__DIR__));
Expand Down
4 changes: 3 additions & 1 deletion src/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

final class Install
{
/** @SuppressWarnings(PHPMD.StaticAccess) */
public function __invoke(Event $event): void
{
$io = $event->getIO();
Expand Down Expand Up @@ -79,7 +80,7 @@ private function getComposerJson(string $vendor, string $package, string $packag
{
$composerJson = $json->read();
$composerJson = array_merge($composerJson, [
'require' => ['php' => sprintf('>=%s.0', substr((string) phpversion(), 0, 3))] + (array) $composerJson['require'],
'require' => ['php' => sprintf('^%s.0', substr((string) phpversion(), 0, 3))] + (array) $composerJson['require'],
'license' => 'proprietary',
'name' => $packageName,
'description' => '',
Expand Down Expand Up @@ -142,6 +143,7 @@ private function modifyFiles(string $vendor, string $project): void
$this->replaceFile('{php_version}', (string) PHP_VERSION_ID, $projectRoot . '/phpcs.xml');
}

/** @SuppressWarnings(PHPMD.ErrorControlOperator) */
private function deleteFiles(string $path): void
{
foreach (array_filter((array) glob($path . '/*')) as $file) {
Expand Down
7 changes: 5 additions & 2 deletions vendor-bin/tools/composer.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{
"name": "bear/qatools",
"description": "QA tools",
"require": {
"doctrine/coding-standard": "^9.0",
"phpmd/phpmd": "^2.9",
"phpmd/phpmd": "^2.10",
"phpmetrics/phpmetrics": "^2.7",
"phpstan/phpstan": "^0.12",
"psalm/plugin-phpunit": "^0.15",
"squizlabs/php_codesniffer": "^3.5",
"slevomat/coding-standard": "^7.0",
"squizlabs/php_codesniffer": "^3.6",
"vimeo/psalm": "^4.7"
}
}
Loading

0 comments on commit e591814

Please sign in to comment.