diff options
author | Felipe Figueroa <amenadiel@gmail.com> | 2020-12-30 13:45:06 +0300 |
---|---|---|
committer | Felipe Figueroa <amenadiel@gmail.com> | 2020-12-30 13:45:06 +0300 |
commit | df17328cd9ae517e28f4228facfe74653f4687aa (patch) | |
tree | b2e2fd1ec2107145a1c18bded121cb22a1a7c479 | |
parent | ea31a8ebb25ab73eebf44fe308ecf73b5e17bd68 (diff) | |
parent | 8ff8b473fb82f8424c8f9780e24fb843fc0f3124 (diff) |
merge with latest dev
-rw-r--r-- | .github/workflows/coding_standards.yml | 2 | ||||
-rw-r--r-- | .phpcs.xml | 28 | ||||
-rw-r--r-- | .reviewdog.yml | 28 | ||||
-rw-r--r-- | Renderer.php | 108 | ||||
-rw-r--r-- | mk_linters.mk | 13 | ||||
-rw-r--r-- | rector.php | 39 | ||||
-rw-r--r-- | src/classes/ADORecordSet.php | 4 | ||||
-rw-r--r-- | src/decorators/ActionUrlDecorator.php | 2 | ||||
-rw-r--r-- | src/decorators/RedirectUrlDecorator.php | 4 |
9 files changed, 191 insertions, 37 deletions
diff --git a/.github/workflows/coding_standards.yml b/.github/workflows/coding_standards.yml index c3c810c4..c8204158 100644 --- a/.github/workflows/coding_standards.yml +++ b/.github/workflows/coding_standards.yml @@ -60,7 +60,7 @@ jobs: coverage: "none" extensions: "${{ env.PHP_EXTENSIONS }}" php-version: "${{ matrix.php_version }}" - tools: composer, phpcs, cs2pr + tools: composer, phpcs, cs2pr, phive - name: Cache Composer uses: "actions/cache@v2.1.1" @@ -1,19 +1,33 @@ <?xml version="1.0"?> <ruleset name="Slim coding standard"> <description>Slim coding standard</description> - <file>lib</file> + <!-- Paths to check --> + <file>tests</file> + <file>src</file> - <exclude-pattern>*/lib/_(boilerplate|bootstrap)\.php$</exclude-pattern> + <exclude-pattern>*/src/router\.php$</exclude-pattern> + <exclude-pattern>*/src/translations/.*$</exclude-pattern> <!-- display progress --> <arg value="p"/> <!-- use colors in output --> <arg name="colors"/> <!-- inherit rules from: --> - <rule ref="PSR2"/> - <rule ref="Generic.Arrays.DisallowLongArraySyntax"/> + <!-- inherit rules from: --> +<rule ref="PSR2"> + <exclude name="PSR2.Classes.PropertyDeclaration.Underscore"/> + <exclude name="PSR2.Methods.MethodDeclaration.Underscore"/> +</rule> +<rule ref="PSR1"> + <exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps"/> +</rule> - <!-- Paths to check --> - <file>Slim</file> - <file>tests</file> + <rule ref="Generic.Arrays.DisallowLongArraySyntax"/> + <rule ref="Generic.Files.LineLength"> + <properties> + <property name="lineLimit" value="170"/> + <property name="absoluteLineLimit" value="190"/> + </properties> + </rule> </ruleset> +
\ No newline at end of file diff --git a/.reviewdog.yml b/.reviewdog.yml index 7a3f065a..a4b3f5da 100644 --- a/.reviewdog.yml +++ b/.reviewdog.yml @@ -4,20 +4,24 @@ runner: level: info psalm: - cmd: vendor/bin/psalm --config=psalm.xml --diff --diff-methods --output-format=checkstyle + cmd: vendor/bin/psalm --config=psalm.xml --diff --output-format=checkstyle level: info - name: checkstyle csfixer: - cmd: vendor/bin/php-cs-fixer fix --config=.php_cs.php --cache-file=.build/phpcs/csfixer.cache --format=checkstyle --dry-run --diff - level: info - name: checkstyle - - phpcs: - cmd: phpcs --standard=.phpcs.xml --parallel=2 --cache=.build/phpcs/php-cs.cache --report=checkstyle src/* + cmd: vendor/bin/php-cs-fixer fix --config=.php_cs.php --cache-file=.build/phpcs/csfixer.cache --format=checkstyle --dry-run --diff level: info - name: checkstyle + format: checkstyle + + phpmd: + cmd: phpmd src/classes Renderer .phpmd.xml + level: info + format: checkstyle + + #phpcs: + #cmd: phpcs --standard=.phpcs.xml --parallel=2 --cache=.build/phpcs/php-cs.cache --report=checkstyle src/* + #level: info + #name: checkstyle - eslint: - cmd: node_modules/.bin/eslint --ext js --ignore-path .eslintignore assets - level: info + #eslint: + #cmd: node_modules/.bin/eslint --ext js --ignore-path .eslintignore assets + #level: info diff --git a/Renderer.php b/Renderer.php new file mode 100644 index 00000000..d3c59538 --- /dev/null +++ b/Renderer.php @@ -0,0 +1,108 @@ +<?php + +/** + * PHPPgAdmin 6.1.3 + */ + +use PHPMD\AbstractRenderer; +use PHPMD\PHPMD; +use PHPMD\Report; + +/** + * This class will render a Java-PMD compatible xml-report. + */ +class Renderer extends AbstractRenderer +{ + /** + * Temporary property that holds the name of the last rendered file, it is + * used to detect the next processed file. + * + * @var string + */ + private $fileName; + + /** + * This method will be called on all renderers before the engine starts the + * real report processing. + */ + public function start(): void + { + $this->getWriter()->write('<?xml version="1.0" encoding="UTF-8" ?>'); + $this->getWriter()->write(\PHP_EOL); + } + + /** + * This method will be called when the engine has finished the source analysis + * phase. + * + * @param \PHPMD\Report $report + */ + public function renderReport(Report $report): void + { + $writer = $this->getWriter(); + $writer->write('<checkstyle version="3.5.3">'); + $writer->write(\PHP_EOL); + + foreach ($report->getRuleViolations() as $violation) { + $fileName = \str_replace(__DIR__ . \DIRECTORY_SEPARATOR, '', $violation->getFileName()); + + if ($this->fileName !== $fileName) { + // Not first file + if (null !== $this->fileName) { + $writer->write(' </file>' . \PHP_EOL); + } + // Store current file name + $this->fileName = $fileName; + + $writer->write(' <file name="' . $fileName . '">' . \PHP_EOL); + } + + $rule = $violation->getRule(); + + $writer->write(' <error'); + $writer->write(' line="' . $violation->getBeginLine() . '"'); + $writer->write(' endline="' . $violation->getEndLine() . '"'); + $writer->write(\sprintf(' severity="%s"', 2 < $rule->getPriority() ? 'warning' : 'error')); + $writer->write(\sprintf(' message="%s (%s, %s) "', \htmlspecialchars($violation->getDescription()), $rule->getName(), $rule->getRuleSetName())); + + $this->maybeAdd('package', $violation->getNamespaceName()); + $this->maybeAdd('externalInfoUrl', $rule->getExternalInfoUrl()); + $this->maybeAdd('function', $violation->getFunctionName()); + $this->maybeAdd('class', $violation->getClassName()); + $this->maybeAdd('method', $violation->getMethodName()); + //$this->_maybeAdd('variable', $violation->getVariableName()); + + $writer->write(' />' . \PHP_EOL); + } + + // Last file and at least one violation + if (null !== $this->fileName) { + $writer->write(' </file>' . \PHP_EOL); + } + + foreach ($report->getErrors() as $error) { + $writer->write(' <file name="' . $error->getFile() . '">'); + $writer->write($error->getFile()); + $writer->write('<error msg="'); + $writer->write(\htmlspecialchars($error->getMessage())); + $writer->write(' severity="error" />' . \PHP_EOL); + } + + $writer->write('</checkstyle>' . \PHP_EOL); + } + + /** + * This method will write a xml attribute named <b>$attr</b> to the output + * when the given <b>$value</b> is not an empty string and is not <b>null</b>. + * + * @param string $attr the xml attribute name + * @param string $value the attribute value + */ + private function maybeAdd($attr, $value): void + { + if (null === $value || '' === \trim($value)) { + return; + } + $this->getWriter()->write(' ' . $attr . '="' . $value . '"'); + } +} diff --git a/mk_linters.mk b/mk_linters.mk index 232bceed..9b4c07ff 100644 --- a/mk_linters.mk +++ b/mk_linters.mk @@ -40,7 +40,7 @@ abort_suggesting_composer: fi check_executable_or_exit_with_phive: - @if [ ! -f "$(executable)" ]; then \ + @if [ ! -e "$(executable)" ]; then \ echo -e "$(GREEN)$(package_name)$(WHITE) $(RED)NOT FOUND$(WHITE) on $(CYAN)$(executable)$(WHITE). " ;\ echo -e "Install it with $(GREEN)phive install $(package_name)$(WHITE)" ;\ echo ;\ @@ -62,18 +62,19 @@ update_baselines: .PHONY:abort_suggesting_composer check_executable_or_exit_with_phive update_baselines phpmd: package_name:=phpmd -phpmd: executable:= $(shell command -v phpmd 2> /dev/null) +phpmd: executable:=tools/phpmd phpmd: @${MAKE} check_executable_or_exit_with_phive executable=$(executable) package_name=$(package_name) --no-print-directory @$(executable) src text .phpmd.xml --exclude=src/help/*,src/translations/* + phpmd_checkstyle: package_name:=phpmd phpmd_checkstyle: executable:=$(shell command -v phpmd 2> /dev/null) phpmd_checkstyle: @$(executable) src json .phpmd.xml --exclude=src/help/*,src/translations/* > temp/phpmd.report.json ;\ echo -e "$(GREEN)Finished PHPMD$(WHITE): waiting 1s" @sleep 1 ;\ - php tools/phpmd_checkstyle.php ;\ + php tools/phpmd_checkstyle ;\ echo -e "$(GREEN)Formatted PHPMD$(WHITE): as checkStyle" cat temp/phpmd.checkstyle.xml | vendor/bin/cs2pr @@ -143,6 +144,12 @@ phpstan_checkstyle: cat temp/phpstan.checkstyle.xml | vendor/bin/cs2pr ;\ echo "" + +rector: + $(eval executable:=vendor/bin/rector) + $(eval package_name:=rector/rector) + @${MAKE} abort_suggesting_composer executable=$(executable) package_name=$(package_name) --no-print-directory + @$(executable) process --ansi --dry-run lint: $(eval executable:=vendor/bin/parallel-lint ) $(eval package_name:=php-parallel-lint/php-parallel-lint ) @@ -2,7 +2,13 @@ declare(strict_types=1); +use PhpParser\Node\Scalar\EncapsedStringPart; +use Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector; +use Rector\CodingStyle\Rector\FuncCall\VersionCompareFuncCallToConstantRector; +use Rector\CodingStyle\Rector\Property\AddFalseDefaultToBoolPropertyRector; +use Rector\CodingStyle\Rector\Switch_\BinarySwitchToIfElseRector; use Rector\Core\Configuration\Option; +use Rector\Core\ValueObject\PhpVersion; use Rector\Php70\Rector\StaticCall\StaticCallOnNonStaticToInstanceCallRector; use Rector\Set\ValueObject\SetList; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; @@ -13,6 +19,7 @@ return static function (ContainerConfigurator $containerConfigurator): void { $parameters->set(Option::AUTO_IMPORT_NAMES, true); $parameters->set(Option::SETS, [ + SetList::CODING_STYLE, SetList::ACTION_INJECTION_TO_CONSTRUCTOR_INJECTION, SetList::ARRAY_STR_FUNCTIONS_TO_STATIC_CALL, SetList::CODE_QUALITY, @@ -22,12 +29,19 @@ return static function (ContainerConfigurator $containerConfigurator): void { SetList::PHP_70, SetList::PHP_71, SetList::PHP_72, - SetList::PHPSTAN, - SetList::PHPUNIT_CODE_QUALITY, - SetList::SOLID, + SetList::PHPUNIT_CODE_QUALITY, + ]); +// + $parameters->set(Option::SKIP, [ - Rector\SOLID\Rector\Property\AddFalseDefaultToBoolPropertyRector::class => [ + VersionCompareFuncCallToConstantRector::class=>[ __DIR__ . '/src',], + + BinarySwitchToIfElseRector::class=>[ __DIR__ . '/src',], + StaticCallOnNonStaticToInstanceCallRector::class=>[ + __DIR__ . '/src', + ], + AddFalseDefaultToBoolPropertyRector::class => [ // single file __DIR__ . '/src/classes/Connection.php', // or directory @@ -35,14 +49,21 @@ return static function (ContainerConfigurator $containerConfigurator): void { ] ]); - $parameters->set(Option::PHP_VERSION_FEATURES, '7.2'); + $parameters->set(Option::PHPSTAN_FOR_RECTOR_PATH, __DIR__ . '/phpstan.neon'); + $parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_72); $parameters->set(Option::ENABLE_CACHE, true); $parameters->set(Option::CACHE_DIR, __DIR__ . '/.build/rector'); $parameters->set(Option::PATHS, [ - __DIR__ . '/src', + __DIR__ . '/src/classes', + __DIR__ . '/src/controllers', + //__DIR__ . '/src/database', + //__DIR__ . '/src/decorators', + //__DIR__ . '/src/middleware', + //__DIR__ . '/src/traits', //__DIR__ . '/tests' ]); - $parameters->set(Option::EXCLUDE_RECTORS, [ - StaticCallOnNonStaticToInstanceCallRector::class, - ]); + + // register single rule + $services = $containerConfigurator->services(); + $services->set(EncapsedStringsToSprintfRector::class); };
\ No newline at end of file diff --git a/src/classes/ADORecordSet.php b/src/classes/ADORecordSet.php index caee69f0..c18a02ff 100644 --- a/src/classes/ADORecordSet.php +++ b/src/classes/ADORecordSet.php @@ -5,11 +5,11 @@ */ namespace PHPPgAdmin; - +use ADORecordSet as ADODBRecordsetClass; /** * Extends ADORecordSet to let correct inference on PHPDoc params. */ -class ADORecordSet extends \ADORecordSet implements \Countable +class ADORecordSet extends ADODBRecordsetClass implements \Countable { /** * Returns the recordCount. diff --git a/src/decorators/ActionUrlDecorator.php b/src/decorators/ActionUrlDecorator.php index 28f56efe..3ffed5fc 100644 --- a/src/decorators/ActionUrlDecorator.php +++ b/src/decorators/ActionUrlDecorator.php @@ -41,6 +41,6 @@ class ActionUrlDecorator extends Decorator } } - return \containerInstance()->subFolder . '/src/views/' . \str_replace('.php', '', $url); + return /*\containerInstance()->subFolder . '/*/'/src/views/' . \str_replace('.php', '', $url); } } diff --git a/src/decorators/RedirectUrlDecorator.php b/src/decorators/RedirectUrlDecorator.php index beff430c..cfb2570d 100644 --- a/src/decorators/RedirectUrlDecorator.php +++ b/src/decorators/RedirectUrlDecorator.php @@ -36,7 +36,7 @@ class RedirectUrlDecorator extends Decorator $varvalue = Decorator::value_url($value, $fields); if ('subject' === $varname) { - $url = '/' . \str_replace('redirect?', 'redirect/' . $varvalue . '?', $url); + $url = \str_replace('redirect?', 'redirect/' . $varvalue . '?', $url); } else { $url .= $sep . $varname . '=' . $varvalue; } @@ -46,7 +46,7 @@ class RedirectUrlDecorator extends Decorator } if ('' !== containerInstance()->subFolder && (0 === \mb_strpos($url, '/')) && (false === \mb_strpos($url, \containerInstance()->subFolder))) { - $url = \str_replace('//', '/', \containerInstance()->subFolder . '/' . $url); + // $url = \str_replace('//', '/', \containerInstance()->subFolder . '/' . $url); } return \str_replace('.php', '', $url); |