Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Commit

Permalink
Merge branch 'next-11614/add-code-tooling' into 'master'
Browse files Browse the repository at this point in the history
NEXT-11614 - Add code style check and static analysis to pipeline

See merge request shopware/6/product/development!216
  • Loading branch information
mitelg committed Oct 26, 2020
2 parents 23330de + 736957b commit 6f94a2f
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 7 deletions.
23 changes: 19 additions & 4 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ variables:
IMAGE_TAG: shopware/development

stages:
- analyze
- unit
- build

Expand All @@ -12,16 +13,30 @@ cache:
- .composer
- .npm

default:
image: composer:1.10
before_script:
- composer install --ignore-platform-reqs --no-interaction --optimize-autoloader --no-suggest --no-scripts --no-progress
- composer install --ignore-platform-reqs --no-interaction --optimize-autoloader --no-suggest --no-progress --working-dir=dev-ops/analyze

Static Analysis:
stage: analyze
only:
refs:
- merge_requests
- master
script:
- dev-ops/analyze/vendor/bin/ecs check src --config easy-coding-standard.php
- dev-ops/analyze/vendor/bin/phpstan analyze --level 8 src
- dev-ops/analyze/vendor/bin/psalm --diff --show-info=false

Unit:
image: composer:1.9
image: composer:1.10
stage: unit
only:
refs:
- merge_requests
- master
before_script:
- composer install --ignore-platform-reqs --no-interaction --optimize-autoloader --no-suggest --no-scripts --no-progress
- composer install --ignore-platform-reqs --no-interaction --optimize-autoloader --no-suggest --no-progress --working-dir=dev-ops/analyze
script:
- vendor/bin/phpunit
--configuration dev-ops/analyze
Expand Down
1 change: 0 additions & 1 deletion dev-ops/common/actions/fix-cs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
#DESCRIPTION: fix code style in src folder

if [ -f "platform/easy-coding-standard.php" ]; then php dev-ops/analyze/vendor/bin/ecs check --fix platform/src --config platform/easy-coding-standard.php; else php dev-ops/analyze/vendor/bin/ecs check --fix platform/src --config platform/easy-coding-standard.yml; fi;
if [ -f "platform/easy-coding-standard.php" ]; then php dev-ops/analyze/vendor/bin/ecs check --fix src --config platform/easy-coding-standard.php; else php dev-ops/analyze/vendor/bin/ecs check --fix platform/src --config platform/easy-coding-standard.yml; fi;
101 changes: 101 additions & 0 deletions easy-coding-standard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Fixer\CastNotation\ModernizeTypesCastingFixer;
use PhpCsFixer\Fixer\ClassNotation\ClassAttributesSeparationFixer;
use PhpCsFixer\Fixer\ClassNotation\SelfAccessorFixer;
use PhpCsFixer\Fixer\FunctionNotation\MethodArgumentSpaceFixer;
use PhpCsFixer\Fixer\FunctionNotation\NullableTypeDeclarationForDefaultNullValueFixer;
use PhpCsFixer\Fixer\FunctionNotation\SingleLineThrowFixer;
use PhpCsFixer\Fixer\FunctionNotation\VoidReturnFixer;
use PhpCsFixer\Fixer\LanguageConstruct\ExplicitIndirectVariableFixer;
use PhpCsFixer\Fixer\Operator\ConcatSpaceFixer;
use PhpCsFixer\Fixer\Phpdoc\GeneralPhpdocAnnotationRemoveFixer;
use PhpCsFixer\Fixer\Phpdoc\NoSuperfluousPhpdocTagsFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocOrderFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocSummaryFixer;
use PhpCsFixer\Fixer\PhpTag\BlankLineAfterOpeningTagFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitConstructFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitDedicateAssertFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitDedicateAssertInternalTypeFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitMockFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitMockShortWillReturnFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitTestCaseStaticMethodCallsFixer;
use PhpCsFixer\Fixer\ReturnNotation\NoUselessReturnFixer;
use PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer;
use PhpCsFixer\Fixer\StringNotation\ExplicitStringVariableFixer;
use PhpCsFixer\Fixer\Whitespace\BlankLineBeforeStatementFixer;
use PhpCsFixer\Fixer\Whitespace\CompactNullableTypehintFixer;
use PhpCsFixerCustomFixers\Fixer\NoImportFromGlobalNamespaceFixer;
use PhpCsFixerCustomFixers\Fixer\NoSuperfluousConcatenationFixer;
use PhpCsFixerCustomFixers\Fixer\NoUselessCommentFixer;
use PhpCsFixerCustomFixers\Fixer\NoUselessParenthesisFixer;
use PhpCsFixerCustomFixers\Fixer\NoUselessStrlenFixer;
use PhpCsFixerCustomFixers\Fixer\OperatorLinebreakFixer;
use PhpCsFixerCustomFixers\Fixer\PhpdocNoIncorrectVarAnnotationFixer;
use PhpCsFixerCustomFixers\Fixer\SingleSpaceAfterStatementFixer;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\CodingStandard\Fixer\ArrayNotation\ArrayListItemNewlineFixer;
use Symplify\CodingStandard\Fixer\ArrayNotation\ArrayOpenerAndCloserNewlineFixer;
use Symplify\EasyCodingStandard\ValueObject\Option;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();

$services->set(ModernizeTypesCastingFixer::class);
$services->set(ClassAttributesSeparationFixer::class)
->call('configure', [['elements' => ['property', 'method']]]);
$services->set(MethodArgumentSpaceFixer::class)
->call('configure', [['on_multiline' => 'ensure_fully_multiline']]);
$services->set(NullableTypeDeclarationForDefaultNullValueFixer::class);
$services->set(VoidReturnFixer::class);
$services->set(ConcatSpaceFixer::class)
->call('configure', [['spacing' => 'one']]);
$services->set(GeneralPhpdocAnnotationRemoveFixer::class)
->call('configure', [['annotations' => ['copyright', 'category']]]);
$services->set(NoSuperfluousPhpdocTagsFixer::class)
->call('configure', [['allow_unused_params' => true]]);
$services->set(PhpdocOrderFixer::class);
$services->set(PhpUnitConstructFixer::class);
$services->set(PhpUnitDedicateAssertFixer::class)
->call('configure', [['target' => 'newest']]);
$services->set(PhpUnitDedicateAssertInternalTypeFixer::class);
$services->set(PhpUnitMockFixer::class);
$services->set(PhpUnitMockShortWillReturnFixer::class);
$services->set(PhpUnitTestCaseStaticMethodCallsFixer::class);
$services->set(NoUselessReturnFixer::class);
$services->set(DeclareStrictTypesFixer::class);
$services->set(BlankLineBeforeStatementFixer::class);
$services->set(CompactNullableTypehintFixer::class);
$services->set(NoImportFromGlobalNamespaceFixer::class);
$services->set(NoSuperfluousConcatenationFixer::class);
$services->set(NoUselessCommentFixer::class);
$services->set(OperatorLinebreakFixer::class);
$services->set(PhpdocNoIncorrectVarAnnotationFixer::class);
$services->set(SingleSpaceAfterStatementFixer::class);
$services->set(NoUselessParenthesisFixer::class);
$services->set(NoUselessStrlenFixer::class);

$parameters = $containerConfigurator->parameters();

$parameters->set(Option::SETS, [
SetList::SYMFONY,
SetList::ARRAY,
SetList::CONTROL_STRUCTURES,
SetList::STRICT,
SetList::PSR_12,
]);

$parameters->set(Option::SKIP, [
ArrayOpenerAndCloserNewlineFixer::class => null,
ArrayListItemNewlineFixer::class => null,
SingleLineThrowFixer::class => null,
SelfAccessorFixer::class => null,
ExplicitIndirectVariableFixer::class => null,
BlankLineAfterOpeningTagFixer::class => null,
PhpdocSummaryFixer::class => null,
ExplicitStringVariableFixer::class => null,
]);
};
24 changes: 24 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<psalm
resolveFromConfigFile="true"
ensureArrayStringOffsetsExist="true"
findUnusedVariablesAndParams="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>

<issueHandlers>
<PropertyNotSetInConstructor>
<errorLevel type="info">
<file name="src/HttpKernel.php"/>
</errorLevel>
</PropertyNotSetInConstructor>
</issueHandlers>
</psalm>
6 changes: 5 additions & 1 deletion src/Command/ConfigDebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
$command = $this->getApplication()->find('debug:config');
$application = $this->getApplication();
if ($application === null) {
throw new \RuntimeException('No Application initialised');
}
$command = $application->find('debug:config');

$bundles = $this->kernel->getBundles();

Expand Down
8 changes: 7 additions & 1 deletion src/Command/DatabaseDebugViewGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 0;
}

protected function updateDatabaseView($tableName, array $viewColumns): void
/**
* @param string[] $viewColumns
*/
protected function updateDatabaseView(string $tableName, array $viewColumns): void
{
$viewName = $this->connection
->quoteIdentifier(self::PREFIX . $tableName);
Expand All @@ -79,6 +82,9 @@ protected function updateDatabaseView($tableName, array $viewColumns): void
$this->connection->exec($createViewSql);
}

/**
* @return string[]
*/
private function getColumns(string $tableName): array
{
$columns = $this->connection->getSchemaManager()->listTableColumns($tableName);
Expand Down

0 comments on commit 6f94a2f

Please sign in to comment.