Skip to content

Commit

Permalink
chore: upgrade PHP 8.3, L11 (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
juampi92 authored Dec 11, 2024
1 parent 2d5fc07 commit bfcf2e5
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 61 deletions.
30 changes: 15 additions & 15 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,26 @@ on:

jobs:
test:
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
os: [ ubuntu-latest ]
php: [ 8.2, 8.1, 8.0 ]
laravel: [ 9.*, 8.*, 10.* ]
stability: [ prefer-stable ]
php: [8.3, 8.2, 8.1]
laravel: [11.*, 10.*, 9.*]
stability: [prefer-stable]
include:
- laravel: 11.*
testbench: 9.*
- laravel: 10.*
testbench: 8.*
- laravel: 9.*
testbench: 7.*
- laravel: 8.*
testbench: ^6.6
- php: 8.1
exclude:
- laravel: 8.*
php: 8.2
- laravel: 9.*
php: 8.0
- laravel: 10.*
php: 8.0
- laravel: 11.*
php: 8.1

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ubuntu-latest

steps:
- name: Checkout code
Expand All @@ -50,7 +46,11 @@ jobs:
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update --ignore-platform-reqs
composer require \
"laravel/framework:${{ matrix.laravel }}" \
"orchestra/testbench:${{ matrix.testbench }}" \
"${{ matrix.php == '8.1' && 'roave/better-reflection:6.25.*' || 'roave/better-reflection:6.*' }}" \
--no-interaction --no-update --ignore-platform-reqs
composer update --${{ matrix.stability }} --prefer-dist --no-interaction --ignore-platform-reqs
- name: Execute tests
run: vendor/bin/phpunit
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
"license": "MIT",
"keywords": ["laravel", "api"],
"require": {
"php" : "^8.0|^8.1|^8.2",
"php" : "^8.1|^8.2|^8.3",
"ext-json": "*",
"illuminate/console": "^8.0|^9.0|^10.0",
"illuminate/contracts": "^8.0|^9.0|^10.0",
"illuminate/filesystem": "^8.0|^9.0|^10.0",
"illuminate/support": "^8.0|^9.0|^10.0",
"roave/better-reflection": "^5.5|^6.1"
"illuminate/console": "^9.0|^10.0|^11.0",
"illuminate/contracts": "^9.0|^10.0|^11.0",
"illuminate/filesystem": "^9.0|^10.0|^11.0",
"illuminate/support": "^9.0|^10.0|^11.0",
"roave/better-reflection": "^6.25"
},
"require-dev": {
"orchestra/testbench": "^5.0|^6.0|^7.0|^8.0",
"nunomaduro/larastan": "^2.3|^1",
"orchestra/testbench": "^6.0|^7.0|^8.0|^9.0",
"friendsofphp/php-cs-fixer": "^3.13",
"phpunit/phpunit": "^9.5"
"phpunit/phpunit": "^9.0|^10.5",
"larastan/larastan": "^2.9"
},
"autoload": {
"psr-4": {
Expand Down
5 changes: 3 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
includes:
- ./vendor/nunomaduro/larastan/extension.neon
- ./vendor/larastan/larastan/extension.neon
- ./phpstan-baseline.neon
parameters:
paths:
- src
level: 7
#excludePaths:
checkMissingIterableValueType: false
reportUnmatchedIgnoredErrors: false
ignoreErrors:
- identifier: missingType.iterableValue
19 changes: 10 additions & 9 deletions src/Application/Baseline/BaselineCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,17 @@ public function getExceededViolations(): Collection

public static function fromViolations(ViolationsCollection $collection): self
{
/** @var Collection<string, Collection<array-key, Violation>> $violationsByIdentifier */
$violationsByIdentifier = $collection->groupBy(fn (Violation $violation): string => $violation->getIdentifier());

return new self(
$collection
->groupBy(fn (Violation $violation): string => $violation->getIdentifier())
->map(
fn (Collection $violations): array => $violations
->groupBy(fn (Violation $violation) => $violation->getTarget())
->map(fn (Collection $violations): int => $violations->count())
->sortKeys()
->all(),
)
$violationsByIdentifier->map(
fn (Collection $violationsByIdentifier): array => $violationsByIdentifier
->groupBy(fn (Violation $violation): string => $violation->getTarget())
->map(fn (Collection $violationsByTarget): int => $violationsByTarget->count())
->sortKeys()
->all(),
)
->all(),
);
}
Expand Down
39 changes: 21 additions & 18 deletions src/Application/Formatters/TableFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,30 @@ public function format(ViolationsCollection $violations): void
return;
}

$violations
->groupBy(fn (Violation $violation): string => $violation->getTarget())
->each(function (ViolationsCollection $violations, string $target) {
$this->style->table(
['Line', $target],
$violations->map(function (Violation $violation): array {
$errorLine = sprintf("%s <options=bold>(%s)</>", $violation->getMessage(), $violation->getIdentifier());
$urlLine = $violation->getUrl() ? "\n<href={$violation->getUrl()}>💡 Read more.</>" : '';
/** @var Collection<string, ViolationsCollection> $violationsGroupedByTarget */
$violationsGroupedByTarget = $violations
->groupBy(fn (Violation $violation): string => $violation->getTarget());

return [
$violation->getLine() ?: '-',
$errorLine . $urlLine,
];
})->all()
);
});
$violationsGroupedByTarget->each(function (ViolationsCollection $violations, string $target) {
$this->style->table(
['Line', $target],
$violations->map(function (Violation $violation): array {
$errorLine = sprintf("%s <options=bold>(%s)</>", $violation->getMessage(), $violation->getIdentifier());
$urlLine = $violation->getUrl() ? "\n<href={$violation->getUrl()}>💡 Read more.</>" : '';

return [
$violation->getLine() ?: '-',
$errorLine . $urlLine,
];
})->all()
);
});

/** @var Collection<string, ViolationsCollection> $violationsGroupedBySeverity */
$violationsGroupedBySeverity = $violations->groupBy(fn (Violation $violation): string => $violation->getSeverity());

/** @var Collection<ViolationSeverity::*, int> $severitiesCount */
$severitiesCount = $violations
->groupBy(fn (Violation $violation): string => $violation->getSeverity())
->map(fn (Collection $violationsCollection): int => $violationsCollection->count());
$severitiesCount = $violationsGroupedBySeverity->map(fn (Collection $violationsCollection): int => $violationsCollection->count());

$errorsCount = (int) $severitiesCount->get(ViolationSeverity::ERROR, 0);
if ($errorsCount > 0) {
Expand Down
6 changes: 5 additions & 1 deletion src/Domain/Pipes/Extractors/ClassExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ class ClassExtractor implements Pipe
*/
public function __invoke($input): Collection
{
if (empty($input->file)) {
return new Collection([]);
}

$astLocator = (new BetterReflection())->astLocator();
$sourceLocator = new AggregateSourceLocator([
new SingleFileSourceLocator($input->file, $astLocator),
new AutoloadSourceLocator(),
]);
$reflector = new DefaultReflector($sourceLocator);
$class = $reflector->reflectAllClasses()[0] ?? null;
$class = $reflector->reflectAllClasses()[0] ?? null; // @phpstan-ignore-line

return new Collection($class ? [$class] : []);
}
Expand Down
12 changes: 8 additions & 4 deletions src/Domain/Pipes/Extractors/MethodExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@

/**
* @implements Pipe<ReflectionClass, ReflectionMethod>
* @phpstan-type Filter = ReflectionMethodFilter::*
*/
class MethodExtractor implements Pipe
{
/** @var Filter|null */
private ?int $filter;

/**
* @param ReflectionMethodFilter::*|null $filter
* @param Filter|null $filter
*/
public function __construct(
?int $filter = null
Expand All @@ -30,8 +32,10 @@ public function __construct(
*/
public function __invoke($input): Collection
{
return collect(
$input->getMethods($this->filter),
);
$methods = $this->filter === null
? $input->getMethods()
: $input->getMethods($this->filter);

return collect($methods);
}
}
4 changes: 2 additions & 2 deletions src/Domain/Pipes/Extractors/NamespaceExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
use Roave\BetterReflection\Reflection\ReflectionClass;

/**
* @implements Pipe<ReflectionClass, string>
* @implements Pipe<ReflectionClass, string|null>
*/
class NamespaceExtractor implements Pipe
{
/**
* @param ReflectionClass $input
* @return Collection<array-key, string>
* @return Collection<array-key, string|null>
*/
public function __invoke($input): Collection
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Violations/ViolationBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function test_should_create_successfully_with_check(): void
public function test_should_fail_when_invalid_data(): void
{
$this->expectException(RuntimeException::class);
$this->expectDeprecationMessageMatches("/The violation must have a message/i");
$this->expectExceptionMessageMatches("/The violation must have a message/i");

ViolationBuilder::make()->build($this->getCheck(), new FileMatch('./tests/Random.php'));
}
Expand Down

0 comments on commit bfcf2e5

Please sign in to comment.