Commit ff6ca4ce authored by David Grüner's avatar David Grüner 🍔
Browse files

Merge branch 'chore/phpstan-improvements' into 'main'

BC break: refactored settings handling, hardened code

See merge request !31
parents c73b5ef7 6e5a7e86
Loading
Loading
Loading
Loading
Loading
+8 −2
Changes for RoboFile.php: 8 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -144,10 +144,16 @@ class RoboFile extends BaseRoboFile

    /**
     * Run tests.
     *
     * @arg string $group Test group
     * @arg string $suite Codeception suite
     */
    public function test(): void
    public function test($group = '', $suite = ''): void
    {
        $this->_execPhp('php ./vendor/bin/codecept run --coverage-xml --coverage-html --coverage-text', true);
        if ($group) {
            $group = "-g {$group}";
        }
        $this->_execPhp("php ./vendor/bin/codecept run {$suite} {$group} --coverage-xml --coverage-html --coverage-text", true);
        $this->outputCoverage();
    }

+7 −0
Changes for composer.json: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -23,7 +23,13 @@
        "ergebnis/composer-normalize": "^2.52",
        "knplabs/knp-menu": "^3.0",
        "liip/imagine-bundle": "^2.0",
        "phpstan/extension-installer": "^1.4",
        "phpstan/phpstan": "^2.2",
        "phpstan/phpstan-deprecation-rules": "^2.0",
        "phpstan/phpstan-phpunit": "^2.0",
        "phpstan/phpstan-strict-rules": "^2.0",
        "phpstan/phpstan-symfony": "^2.0",
        "phpstan/phpstan-webmozart-assert": "^2.0",
        "rector/rector": "^2.5",
        "symfony-cmf/routing": "^3.0",
        "symfony/flex": "^2.11",
@@ -49,6 +55,7 @@
    "config": {
        "allow-plugins": {
            "ergebnis/composer-normalize": true,
            "phpstan/extension-installer": true,
            "symfony/flex": true
        },
        "sort-packages": true
+1 −1
Changes for phpstan.dist.neon: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@ includes:
    - phpstan-baseline.neon

parameters:
  level: 6
  level: 10
  tmpDir: .robo/cache/phpstan
  paths:
    - src
+2 −2
Changes for rector.php: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -3,11 +3,11 @@
declare(strict_types=1);

use Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector;
use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector;
use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector;
use Rector\Config\RectorConfig;
use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitSelfCallRector;
use Rector\PHPUnit\PHPUnit120\Rector\CallLike\CreateStubOverCreateMockArgRector;
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
use Rector\Symfony\Symfony72\Rector\StmtsAwareInterface\PushRequestToRequestStackConstructorRector;

return RectorConfig::configure()
@@ -47,10 +47,10 @@ return RectorConfig::configure()
    ->withRules([
        PreferPHPUnitSelfCallRector::class,
        CreateStubOverCreateMockArgRector::class,
        DisallowedEmptyRuleFixerRector::class,
    ])

    ->withSkip([
        CountArrayToEmptyArrayComparisonRector::class,
        EncapsedStringsToSprintfRector::class,
        NewlineAfterStatementRector::class,

+6 −10
Changes for src/Content/BasicWritablePageTrait.php: 6 added lines, 10 removed lines.
Original line number Diff line number Diff line
@@ -2,15 +2,11 @@

namespace ZeroGravity\Cms\Content;

use ZeroGravity\Cms\Content\Meta\PageSettings;
use ZeroGravity\Cms\Filesystem\Directory;

/**
 * @phpstan-import-type SettingValue from PageSettings
 */
trait BasicWritablePageTrait
{
    private ?string $contentRaw = null;
    private string $contentRaw = '';

    private readonly ?Directory $directory;

@@ -32,7 +28,7 @@ trait BasicWritablePageTrait
    /**
     * Get raw (un-processed) markdown content.
     */
    public function getContentRaw(): ?string
    public function getContentRaw(): string
    {
        return $this->contentRaw;
    }
@@ -40,19 +36,19 @@ trait BasicWritablePageTrait
    /**
     * Set raw (un-processed) markdown content.
     */
    public function setContentRaw(?string $contentRaw = null): void
    public function setContentRaw(string $contentRaw = ''): void
    {
        $this->contentRaw = str_replace("\r\n", "\n", (string) $contentRaw);
        $this->contentRaw = str_replace("\r\n", "\n", $contentRaw);
    }

    /**
     * Set page settings as plain array.
     *
     * @param array<string, SettingValue> $settings
     * @param array<string, mixed> $settings raw, unvalidated settings as passed to the OptionsResolver
     */
    public function setSettings(array $settings): void
    {
        $this->settings = new PageSettings($settings, $this->getName());
        $this->initSettings($settings, $this->name);
        $this->buildPath();
    }

Loading