diff --git a/.github/workflows/deduplicate.yml b/.github/workflows/deduplicate.yml deleted file mode 100644 index 827bbbc..0000000 --- a/.github/workflows/deduplicate.yml +++ /dev/null @@ -1,39 +0,0 @@ -# When a PR is opened or a push is made, check code -# for duplication with PHP Copy/Paste Detector. -name: PHPCPD - -on: - pull_request: - branches: - - 'develop' - paths: - - 'app/**' - - 'src/**' - - 'tests/**' - - '.github/workflows/deduplicate.yml' - push: - branches: - - 'develop' - paths: - - 'app/**' - - 'src/**' - - 'tests/**' - - '.github/workflows/deduplicate.yml' - -jobs: - build: - name: Duplicate Code Detection - 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: phpcpd - extensions: dom, mbstring - - - name: Detect code duplication - run: phpcpd app/ src/ tests/ diff --git a/.github/workflows/inspect.yml b/.github/workflows/deptrac.yml similarity index 54% rename from .github/workflows/inspect.yml rename to .github/workflows/deptrac.yml index 23440fe..528cdc4 100644 --- a/.github/workflows/inspect.yml +++ b/.github/workflows/deptrac.yml @@ -1,41 +1,40 @@ -# When a PR is opened or a push is made, perform an -# architectural inspection on the code using Deptrac. name: Deptrac on: pull_request: branches: - - 'develop' + - develop paths: - - 'src/**' - - 'tests/**' + - '**.php' - 'composer.**' - 'depfile.yaml' - - '.github/workflows/inspect.yml' + - '.github/workflows/deptrac.yml' push: branches: - - 'develop' + - develop paths: - - 'src/**' - - 'tests/**' + - '**.php' - 'composer.**' - 'depfile.yaml' - - '.github/workflows/inspect.yml' + - '.github/workflows/deptrac.yml' jobs: build: - name: Architectural Inspection + name: Dependency Tracing runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, '[ci skip]')" + steps: - name: Checkout uses: actions/checkout@v2 - - name: Setup PHP + - name: Set up PHP uses: shivammathur/setup-php@v2 with: php-version: '8.0' - tools: composer, pecl, phive + tools: phive extensions: intl, json, mbstring, xml + coverage: none env: COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -43,14 +42,11 @@ jobs: id: composer-cache run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - name: Create composer cache directory - run: mkdir -p ${{ steps.composer-cache.outputs.dir }} - - name: Cache composer dependencies uses: actions/cache@v2 with: path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - name: Create Deptrac cache directory @@ -63,17 +59,16 @@ jobs: key: ${{ runner.os }}-deptrac-${{ github.sha }} restore-keys: ${{ runner.os }}-deptrac- - - name: Install dependencies (limited) - if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name }} - run: composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader - - - name: Install dependencies (authenticated) - if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name }} - run: composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader - env: - COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }} + - name: Install dependencies + run: | + composer -q config -g github-oauth.github.com "${{ secrets.GITHUB_TOKEN }}" + if [ -f composer.lock ]; then + composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader + else + composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader + fi - - name: Run architectural inspection + - name: Trace dependencies run: | sudo phive --no-progress install --global --trust-gpg-keys B8F640134AB1782E,A98E898BB53EB748 qossmic/deptrac deptrac analyze --cache-file=build/deptrac.cache diff --git a/.github/workflows/infection.yml b/.github/workflows/infection.yml new file mode 100644 index 0000000..2e5d05d --- /dev/null +++ b/.github/workflows/infection.yml @@ -0,0 +1,73 @@ +name: Infection + +on: + pull_request: + branches: + - develop + paths: + - '**.php' + - 'composer.**' + - 'phpunit*' + - '.github/workflows/infection.yml' + push: + branches: + - develop + paths: + - '**.php' + - 'composer.**' + - 'phpunit*' + - '.github/workflows/infection.yml' + +jobs: + main: + name: Mutation Testing + runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, '[ci skip]')" + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Set up PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.0' + tools: infection, phpunit + extensions: intl, json, mbstring, gd, xml, sqlite3 + coverage: xdebug + env: + COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up problem matchers for PHPUnit + run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - name: Configure matchers + uses: mheap/phpunit-matcher-action@v1 + + - name: Get composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache composer dependencies + uses: actions/cache@v2 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install dependencies + run: | + composer -q config -g github-oauth.github.com "${{ secrets.GITHUB_TOKEN }}" + if [ -f composer.lock ]; then + composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader + else + composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader + fi + + - name: Test with PHPUnit + run: vendor/bin/phpunit --teamcity + + - name: Mutate with Infection + run: | + git fetch --depth=1 origin $GITHUB_BASE_REF + infection --threads=2 --skip-initial-tests --coverage=build/phpunit --git-diff-base=origin/$GITHUB_BASE_REF --git-diff-filter=AM --logger-github --ignore-msi-with-no-mutations diff --git a/.github/workflows/phpcpd.yml b/.github/workflows/phpcpd.yml new file mode 100644 index 0000000..2c9d209 --- /dev/null +++ b/.github/workflows/phpcpd.yml @@ -0,0 +1,36 @@ +name: PHPCPD + +on: + pull_request: + branches: + - develop + paths: + - '**.php' + - '.github/workflows/phpcpd.yml' + push: + branches: + - develop + paths: + - '**.php' + - '.github/workflows/phpcpd.yml' + +jobs: + build: + name: Code Copy-Paste Detection + runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, '[ci skip]')" + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.0' + tools: phpcpd + extensions: dom, mbstring + coverage: none + + - name: Detect duplicate code + run: phpcpd src/ tests/ diff --git a/.github/workflows/phpcsfixer.yml b/.github/workflows/phpcsfixer.yml new file mode 100644 index 0000000..6dd670f --- /dev/null +++ b/.github/workflows/phpcsfixer.yml @@ -0,0 +1,61 @@ +name: PHPCSFixer + +on: + pull_request: + branches: + - develop + paths: + - '**.php' + - '.github/workflows/phpcsfixer.yml' + push: + branches: + - develop + paths: + - '**.php' + - '.github/workflows/phpcsfixer.yml' + +jobs: + build: + name: PHP ${{ matrix.php-versions }} Coding Standards + runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, '[ci skip]')" + strategy: + fail-fast: false + matrix: + php-versions: ['7.4', '8.0', '8.1'] + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Set up PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: json, tokenizer + coverage: none + env: + COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Get composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache composer dependencies + uses: actions/cache@v2 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install dependencies + run: | + composer -q config -g github-oauth.github.com "${{ secrets.GITHUB_TOKEN }}" + if [ -f composer.lock ]; then + composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader + else + composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader + fi + + - name: Check code for standards compliance + run: vendor/bin/php-cs-fixer fix --verbose --ansi --dry-run --using-cache=no --diff diff --git a/.github/workflows/analyze.yml b/.github/workflows/phpstan.yml similarity index 53% rename from .github/workflows/analyze.yml rename to .github/workflows/phpstan.yml index 12c48c1..38300b9 100644 --- a/.github/workflows/analyze.yml +++ b/.github/workflows/phpstan.yml @@ -1,35 +1,33 @@ -# When a PR is opened or a push is made, perform -# a static analysis check on the code using PHPStan. name: PHPStan on: pull_request: branches: - - 'develop' + - develop paths: - - 'src/**' - - 'tests/**' + - '**.php' - 'composer.**' - 'phpstan*' - - '.github/workflows/analyze.yml' + - '.github/workflows/phpstan.yml' push: branches: - - 'develop' + - develop paths: - - 'src/**' - - 'tests/**' + - '**.php' - 'composer.**' - 'phpstan*' - - '.github/workflows/analyze.yml' + - '.github/workflows/phpstan.yml' jobs: build: name: PHP ${{ matrix.php-versions }} Static Analysis runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, '[ci skip]')" strategy: fail-fast: false matrix: - php-versions: ['7.3', '7.4', '8.0'] + php-versions: ['7.4', '8.0', '8.1'] + steps: - name: Checkout uses: actions/checkout@v2 @@ -38,8 +36,9 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-versions }} - tools: composer, pecl, phpunit - extensions: intl, json, mbstring, gd, mysqlnd, xdebug, xml, sqlite3 + tools: phpstan, phpunit + extensions: intl, json, mbstring, xml + coverage: none env: COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -47,14 +46,11 @@ jobs: id: composer-cache run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - name: Create composer cache directory - run: mkdir -p ${{ steps.composer-cache.outputs.dir }} - - name: Cache composer dependencies uses: actions/cache@v2 with: path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - name: Create PHPStan cache directory @@ -67,15 +63,14 @@ jobs: key: ${{ runner.os }}-phpstan-${{ github.sha }} restore-keys: ${{ runner.os }}-phpstan- - - name: Install dependencies (limited) - if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name }} - run: composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader - - - name: Install dependencies (authenticated) - if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name }} - run: composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader - env: - COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }} + - name: Install dependencies + run: | + composer -q config -g github-oauth.github.com "${{ secrets.GITHUB_TOKEN }}" + if [ -f composer.lock ]; then + composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader + else + composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader + fi - name: Run static analysis run: vendor/bin/phpstan analyze diff --git a/.github/workflows/test.yml b/.github/workflows/phpunit.yml similarity index 62% rename from .github/workflows/test.yml rename to .github/workflows/phpunit.yml index 99942fb..e1ba40e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/phpunit.yml @@ -4,32 +4,39 @@ on: pull_request: branches: - develop + paths: + - '**.php' + - 'composer.**' + - 'phpunit*' + - '.github/workflows/phpunit.yml' push: branches: - develop + paths: + - '**.php' + - 'composer.**' + - 'phpunit*' + - '.github/workflows/phpunit.yml' jobs: main: name: PHP ${{ matrix.php-versions }} Unit Tests - - strategy: - matrix: - php-versions: ['7.3', '7.4', '8.0'] - runs-on: ubuntu-latest - if: "!contains(github.event.head_commit.message, '[ci skip]')" + strategy: + matrix: + php-versions: ['7.4', '8.0', '8.1'] steps: - name: Checkout uses: actions/checkout@v2 - - name: Setup PHP, with composer and extensions + - name: Set up PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-versions }} - tools: composer, infection, pecl, phive, phpunit - extensions: intl, json, mbstring, gd, mysqlnd, xdebug, xml, sqlite3 + tools: composer, phive, phpunit + extensions: intl, json, mbstring, gd, xdebug, xml, sqlite3 coverage: xdebug env: COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -42,18 +49,17 @@ jobs: uses: actions/cache@v2 with: path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - - name: Install dependencies (limited) - if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name }} - run: composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader - - - name: Install dependencies (authenticated) - if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name }} - run: composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader - env: - COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }} + - name: Install dependencies + run: | + composer -q config -g github-oauth.github.com "${{ secrets.GITHUB_TOKEN }}" + if [ -f composer.lock ]; then + composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader + else + composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader + fi - name: Test with PHPUnit run: vendor/bin/phpunit --verbose --coverage-text @@ -61,12 +67,6 @@ jobs: TERM: xterm-256color TACHYCARDIA_MONITOR_GA: enabled - - if: matrix.php-versions == '8.0' - name: Mutate with Infection - run: | - git fetch --depth=1 origin $GITHUB_BASE_REF - infection --threads=2 --skip-initial-tests --coverage=build/phpunit --git-diff-base=origin/$GITHUB_BASE_REF --git-diff-filter=AM --logger-github --ignore-msi-with-no-mutations - - if: matrix.php-versions == '8.0' name: Run Coveralls continue-on-error: true diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml new file mode 100644 index 0000000..fff0208 --- /dev/null +++ b/.github/workflows/rector.yml @@ -0,0 +1,68 @@ +name: Rector + +on: + pull_request: + branches: + - develop + paths: + - '**.php' + - 'composer.**' + - 'rector.php' + - '.github/workflows/rector.yml' + push: + branches: + - develop + paths: + - '**.php' + - 'composer.**' + - 'rector.php' + - '.github/workflows/rector.yml' + +jobs: + build: + name: PHP ${{ matrix.php-versions }} Rector Analysis + runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, '[ci skip]')" + strategy: + fail-fast: false + matrix: + php-versions: ['7.4', '8.0', '8.1'] + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Set up PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + tools: phpstan + extensions: intl, json, mbstring, xml + coverage: none + env: + COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Get composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache composer dependencies + uses: actions/cache@v2 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install dependencies + run: | + composer -q config -g github-oauth.github.com "${{ secrets.GITHUB_TOKEN }}" + if [ -f composer.lock ]; then + composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader + else + composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader + fi + + - name: Analyze for refactoring + run: | + composer global require --dev rector/rector:^0.12.10 + rector process --dry-run --no-progress-bar diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index dfa45af..1185b9c 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -6,7 +6,10 @@ $finder = Finder::create() ->files() - ->in(__DIR__) + ->in([ + __DIR__ . '/src/', + __DIR__ . '/tests/', + ]) ->exclude('build') ->append([__FILE__]); diff --git a/composer.json b/composer.json index 6a58489..8f749df 100644 --- a/composer.json +++ b/composer.json @@ -22,11 +22,11 @@ } ], "require": { - "php": "^7.3 || ^8.0", + "php": "^7.4 || ^8.0", "almasaeed2010/adminlte": "^3.0", + "components/jquery": "^3.3", "datatables.net/datatables.net-bs4": "dev-master", "fortawesome/font-awesome": "^5.15", - "components/jquery": "^3.3", "league/commonmark": "^2.0", "tatter/alerts": "^3.0", "tatter/assets": "^3.0", @@ -36,8 +36,13 @@ "twbs/bootstrap": "^4.0" }, "require-dev": { - "codeigniter4/codeigniter4": "dev-develop", - "tatter/tools": "^1.15" + "codeigniter4/devkit": "^1.0", + "codeigniter4/framework": "^4.1" + }, + "config": { + "allow-plugins": { + "phpstan/extension-installer": true + } }, "autoload": { "psr-4": { @@ -53,10 +58,6 @@ } }, "repositories": [ - { - "type": "vcs", - "url": "https://github.com/codeigniter4/CodeIgniter4.git" - }, { "type": "vcs", "url": "https://github.com/DataTables/Dist-DataTables-Bootstrap4.git" @@ -76,17 +77,14 @@ "@analyze", "@test", "@inspect", + "rector process", "@style" ], "deduplicate": "phpcpd app/ src/", "inspect": "deptrac analyze --cache-file=build/deptrac.cache", "mutate": "infection --threads=2 --skip-initial-tests --coverage=build/phpunit", + "retool": "retool", "style": "php-cs-fixer fix --verbose --ansi --using-cache=no", "test": "phpunit" - }, - "config": { - "allow-plugins": { - "phpstan/extension-installer": true - } } } diff --git a/depfile.yaml b/depfile.yaml index 4ca1cc7..e5ed3df 100644 --- a/depfile.yaml +++ b/depfile.yaml @@ -1,7 +1,7 @@ paths: - - ./src - - ./vendor/codeigniter4/codeigniter4/system - - ./vendor/tatter + - ./src/ + - ./vendor/codeigniter4/framework/system/ + - ./vendor/tatter/ exclude_files: - '#.*test.*#i' layers: diff --git a/infection.json.dist b/infection.json.dist index b175102..7badcc6 100644 --- a/infection.json.dist +++ b/infection.json.dist @@ -1,7 +1,7 @@ { "source": { "directories": [ - "src" + "src/" ], "excludes": [ "Config", @@ -15,5 +15,5 @@ "mutators": { "@default": true }, - "bootstrap": "vendor/codeigniter4/codeigniter4/system/Test/bootstrap.php" + "bootstrap": "vendor/codeigniter4/framework/system/Test/bootstrap.php" } diff --git a/phpstan.neon.dist b/phpstan.neon.dist index b8d844f..f27f414 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -2,11 +2,12 @@ parameters: tmpDir: build/phpstan level: 5 paths: - - src - - tests + - src/ + - tests/ bootstrapFiles: - - vendor/codeigniter4/codeigniter4/system/Test/bootstrap.php + - vendor/codeigniter4/framework/system/Test/bootstrap.php excludePaths: + - src/Config/Routes.php - src/Views/* ignoreErrors: universalObjectCratesClasses: @@ -14,7 +15,7 @@ parameters: - CodeIgniter\Entity\Entity - Faker\Generator scanDirectories: - - vendor/codeigniter4/codeigniter4/system/Helpers + - vendor/codeigniter4/framework/system/Helpers dynamicConstantNames: - APP_NAMESPACE - CI_DEBUG diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a90a1f2..ac88cfc 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,7 +1,7 @@ - ./src + ./src/ + ./src/Config ./src/Views - ./src/Config/Routes.php @@ -37,7 +37,7 @@ - + ./tests @@ -74,16 +74,16 @@ - + - + - + diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..fab090d --- /dev/null +++ b/rector.php @@ -0,0 +1,125 @@ +import(SetList::DEAD_CODE); + $containerConfigurator->import(LevelSetList::UP_TO_PHP_74); + $containerConfigurator->import(PHPUnitSetList::PHPUNIT_SPECIFIC_METHOD); + $containerConfigurator->import(PHPUnitSetList::PHPUNIT_80); + + $parameters = $containerConfigurator->parameters(); + + $parameters->set(Option::PARALLEL, true); + // The paths to refactor (can also be supplied with CLI arguments) + $parameters->set(Option::PATHS, [ + __DIR__ . '/src/', + __DIR__ . '/tests/', + ]); + + // Include Composer's autoload - required for global execution, remove if running locally + $parameters->set(Option::AUTOLOAD_PATHS, [ + __DIR__ . '/vendor/autoload.php', + ]); + + // Do you need to include constants, class aliases, or a custom autoloader? + $parameters->set(Option::BOOTSTRAP_FILES, [ + realpath(getcwd()) . '/vendor/codeigniter4/framework/system/Test/bootstrap.php', + ]); + + if (is_file(__DIR__ . '/phpstan.neon.dist')) { + $parameters->set(Option::PHPSTAN_FOR_RECTOR_PATH, __DIR__ . '/phpstan.neon.dist'); + } + + // Set the target version for refactoring + $parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_74); + + // Auto-import fully qualified class names + $parameters->set(Option::AUTO_IMPORT_NAMES, true); + + // Are there files or rules you need to skip? + $parameters->set(Option::SKIP, [ + __DIR__ . '/src/Views', + + JsonThrowOnErrorRector::class, + StringifyStrNeedlesRector::class, + + // Note: requires php 8 + RemoveUnusedPromotedPropertyRector::class, + + // Ignore tests that might make calls without a result + RemoveEmptyMethodCallRector::class => [ + __DIR__ . '/tests', + ], + + // Ignore files that should not be namespaced + NormalizeNamespaceByPSR4ComposerAutoloadRector::class => [ + __DIR__ . '/src/Helpers', + ], + + // May load view files directly when detecting classes + StringClassNameToClassConstantRector::class, + + // May be uninitialized on purpose + AddDefaultValueForUndefinedVariableRector::class, + ]); + + // Additional rules to apply + $services = $containerConfigurator->services(); + $services->set(SimplifyUselessVariableRector::class); + $services->set(RemoveAlwaysElseRector::class); + $services->set(CountArrayToEmptyArrayComparisonRector::class); + $services->set(ForToForeachRector::class); + $services->set(ChangeNestedForeachIfsToEarlyContinueRector::class); + $services->set(ChangeIfElseValueAssignToEarlyReturnRector::class); + $services->set(SimplifyStrposLowerRector::class); + $services->set(CombineIfRector::class); + $services->set(SimplifyIfReturnBoolRector::class); + $services->set(InlineIfToExplicitIfRector::class); + $services->set(PreparedValueToEarlyReturnRector::class); + $services->set(ShortenElseIfRector::class); + $services->set(SimplifyIfElseToTernaryRector::class); + $services->set(UnusedForeachValueToArrayKeysRector::class); + $services->set(ChangeArrayPushToArrayAssignRector::class); + $services->set(UnnecessaryTernaryExpressionRector::class); + $services->set(AddPregQuoteDelimiterRector::class); + $services->set(SimplifyRegexPatternRector::class); + $services->set(FuncGetArgsToVariadicParamRector::class); + $services->set(MakeInheritedMethodVisibilitySameAsParentRector::class); + $services->set(SimplifyEmptyArrayCheckRector::class); + $services->set(NormalizeNamespaceByPSR4ComposerAutoloadRector::class); +}; diff --git a/src/FrontendBundle.php b/src/FrontendBundle.php index e0ca940..cc5efd1 100644 --- a/src/FrontendBundle.php +++ b/src/FrontendBundle.php @@ -17,10 +17,8 @@ abstract class FrontendBundle extends Bundle { /** * The base directory, i.e. Assets directory + vendor path - * - * @var string|null */ - private static $base; + private static ?string $base = null; /** * Returns the base path according to the configurations. diff --git a/src/FrontendPublisher.php b/src/FrontendPublisher.php index ff05abc..bdbdc9b 100644 --- a/src/FrontendPublisher.php +++ b/src/FrontendPublisher.php @@ -18,17 +18,15 @@ abstract class FrontendPublisher extends Publisher /** * Destination path relative to AssetsConfig::directory. * Must be set by child classes. - * - * @var string */ - protected $path; + protected string $path = ''; /** * Set the real destination. */ public function __construct(?string $source = null, ?string $destination = null) { - if (! is_string($this->path)) { + if ($this->path === '') { throw new DomainException('Invalid relative destination $path.'); } diff --git a/src/Publishers/AdminLTEPublisher.php b/src/Publishers/AdminLTEPublisher.php index bced3a4..5d59326 100644 --- a/src/Publishers/AdminLTEPublisher.php +++ b/src/Publishers/AdminLTEPublisher.php @@ -6,6 +6,6 @@ class AdminLTEPublisher extends FrontendPublisher { - protected $source = 'vendor/almasaeed2010/adminlte/dist'; - protected $path = 'adminlte'; + protected $source = 'vendor/almasaeed2010/adminlte/dist'; + protected string $path = 'adminlte'; } diff --git a/src/Publishers/BootstrapPublisher.php b/src/Publishers/BootstrapPublisher.php index 3360245..9a99d5b 100644 --- a/src/Publishers/BootstrapPublisher.php +++ b/src/Publishers/BootstrapPublisher.php @@ -6,6 +6,6 @@ class BootstrapPublisher extends FrontendPublisher { - protected $source = 'vendor/twbs/bootstrap/dist'; - protected $path = 'bootstrap'; + protected $source = 'vendor/twbs/bootstrap/dist'; + protected string $path = 'bootstrap'; } diff --git a/src/Publishers/DataTablesPublisher.php b/src/Publishers/DataTablesPublisher.php index c7e0bff..8d9c66d 100644 --- a/src/Publishers/DataTablesPublisher.php +++ b/src/Publishers/DataTablesPublisher.php @@ -6,8 +6,8 @@ class DataTablesPublisher extends FrontendPublisher { - protected $source = 'vendor/datatables.net/datatables.net'; - protected $path = 'datatables'; + protected $source = 'vendor/datatables.net/datatables.net'; + protected string $path = 'datatables'; /** * Reads files from the sources and copies them out to their destinations. diff --git a/src/Publishers/DataTablesStylePublisher.php b/src/Publishers/DataTablesStylePublisher.php index af07fe9..47f522a 100644 --- a/src/Publishers/DataTablesStylePublisher.php +++ b/src/Publishers/DataTablesStylePublisher.php @@ -6,8 +6,8 @@ class DataTablesStylePublisher extends FrontendPublisher { - protected $source = 'vendor/datatables.net/datatables.net-bs4'; - protected $path = 'datatables'; + protected $source = 'vendor/datatables.net/datatables.net-bs4'; + protected string $path = 'datatables'; /** * Reads files from the sources and copies them out to their destinations. diff --git a/src/Publishers/FontAwesomePublisher.php b/src/Publishers/FontAwesomePublisher.php index 3bd177e..f42bbca 100644 --- a/src/Publishers/FontAwesomePublisher.php +++ b/src/Publishers/FontAwesomePublisher.php @@ -6,19 +6,8 @@ class FontAwesomePublisher extends FrontendPublisher { - /** - * @var string - */ - protected $source = 'vendor/fortawesome/font-awesome'; - - /** - * Destination path relative to AssetsConfig::directory. - * - * @see FrontendPublisher::__construct() - * - * @var string - */ - protected $path = 'font-awesome'; + protected $source = 'vendor/fortawesome/font-awesome'; + protected string $path = 'font-awesome'; /** * Reads files from the sources and copies them out to their destinations. diff --git a/src/Publishers/JQueryPublisher.php b/src/Publishers/JQueryPublisher.php index 44bea3e..4e7ed4d 100644 --- a/src/Publishers/JQueryPublisher.php +++ b/src/Publishers/JQueryPublisher.php @@ -6,6 +6,6 @@ class JQueryPublisher extends FrontendPublisher { - protected $source = 'vendor/components/jquery'; - protected $path = 'jquery'; + protected $source = 'vendor/components/jquery'; + protected string $path = 'jquery'; } diff --git a/tests/FrontendPublisherTest.php b/tests/FrontendPublisherTest.php index 33c25f4..3b0ec55 100644 --- a/tests/FrontendPublisherTest.php +++ b/tests/FrontendPublisherTest.php @@ -16,7 +16,7 @@ public function testPublisherThrowsWithoutPath() $this->expectException('DomainException'); $this->expectExceptionMessage('Invalid relative destination $path'); - $publisher = new class () extends FrontendPublisher { + new class () extends FrontendPublisher { }; } @@ -25,8 +25,8 @@ public function testPublisherSetsDestination() // Allow publishing to the test folder config('Publisher')->restrictions[SUPPORTPATH] = '*'; - $publisher = new class () extends FrontendPublisher { - protected $path = 'foobar'; + $publisher = new class () extends FrontendPublisher { + protected string $path = 'foobar'; }; $this->assertSame($this->assets->directory . 'vendor/foobar/', $publisher->getDestination());