Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 12 additions & 31 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,51 +91,29 @@ jobs:
- name: "Run shipmonk/composer-dependency-analyser"
run: "vendor/bin/composer-dependency-analyser"

static-code-analysis:
Comment thread
Hanmac marked this conversation as resolved.
name: "Static Code Analysis"
phpstan:
name: "PHPStan"

runs-on: "ubuntu-latest"

strategy:
matrix:
php-version:
- "8.1"
- "8.2"
- "8.3"
- "8.4"

dependencies:
- "highest"

symfony:
- "^5.4"
- "^6.0"
- "^7.0"

exclude:
- php-version: "8.1"
symfony: "^7.0"
steps:
- name: "Checkout"
uses: "actions/checkout@v4"

- name: "Setup PHP, with composer and extensions"
- name: "Install PHP with extensions"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"
extensions: "${{ env.PHP_EXTENSIONS }}"
php-version: '8.4'
coverage: "none"
tools: "flex"
tools: "composer:v2"

- name: "Install composer dependencies"
- name: "Install Composer dependencies (highest)"
uses: "ramsey/composer-install@v3"
env:
SYMFONY_REQUIRE: "${{ matrix.symfony }}"
with:
dependency-versions: "${{ matrix.dependencies }}"
dependency-versions: "highest"

- name: "Static analysis"
run: "vendor/bin/psalm --php-version=${{ matrix.php-version }}"
- name: "PHPStan"
run: "vendor/bin/phpstan --no-progress --memory-limit=1G analyse --error-format=github"

unit-tests:
name: "Unit tests"
Expand All @@ -162,6 +140,9 @@ jobs:
exclude:
- php-version: "8.1"
symfony: "^7.0"
include:
- php-version: '8.4'
symfony: '^8.0.0'

steps:
- name: "Checkout"
Expand Down
4 changes: 4 additions & 0 deletions composer-dependency-analyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use ShipMonk\ComposerDependencyAnalyser\Config\Configuration;
use ShipMonk\ComposerDependencyAnalyser\Config\ErrorType;
use Symfony\Component\TypeInfo\Type;
use Symfony\Component\PropertyInfo\Type as LegacyType;

$config = new Configuration();

Expand All @@ -16,6 +17,9 @@
} else {
$config->ignoreUnknownClasses([Type::class]);
}
if (!class_exists(LegacyType::class)) {
$config->ignoreUnknownClasses([LegacyType::class]);
}

// ignore polyfill
if (version_compare(PHP_VERSION, '8.3.0', '>=')) {
Expand Down
29 changes: 17 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,33 @@
"require": {
"php": ">=8.1",
"doctrine/dbal": "^3.4 || ^4.0",
"doctrine/doctrine-bundle": "^1.9 || ^2.0 || ^3.0",
"doctrine/doctrine-bundle": "^1.9 || ^2.0 || ^3.0 || ^4.0",
"dragonmantank/cron-expression": "^2.2 || ^3.0",
"symfony/config": "^5.4 || ^6.0 || ^7.0",
"symfony/dependency-injection": "^5.4 || ^6.0 || ^7.0",
"symfony/form": "^5.4 || ^6.0 || ^7.0",
"symfony/http-kernel": "^5.4 || ^6.0 || ^7.0",
"symfony/options-resolver": "^5.4 || ^6.0 || ^7.0",
"symfony/config": "^5.4 || ^6.0 || ^7.0 || ^8.0",
"symfony/dependency-injection": "^5.4 || ^6.0 || ^7.0 || ^8.0",
"symfony/form": "^5.4 || ^6.0 || ^7.0 || ^8.0",
"symfony/http-kernel": "^5.4 || ^6.0 || ^7.0 || ^8.0",
"symfony/options-resolver": "^5.4 || ^6.0 || ^7.0 || ^8.0",
"symfony/polyfill-php83": "^1.33",
"symfony/polyfill-php84": "^1.33",
"symfony/property-info": "^5.4 || ^6.0 || ^7.0",
"symfony/validator": "^5.4 || ^6.0 || ^7.0"
"symfony/property-info": "^5.4 || ^6.0 || ^7.0 || ^8.0",
"symfony/validator": "^5.4 || ^6.0 || ^7.0 || ^8.0"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.42",
"matthiasnoback/symfony-dependency-injection-test": "^4.3 || ^5.0 || ^6.0",
"phpdocumentor/reflection-docblock": "^5.3",
"phpstan/extension-installer": "^1.0",
"phpstan/phpdoc-parser": "^1.0 || ^2.0",
"phpstan/phpstan": "^1.0 || ^2.0",
"phpstan/phpstan-phpunit": "^1.0 || ^2.0",
"phpstan/phpstan-strict-rules": "^1.0 || ^2.0",
"phpstan/phpstan-symfony": "^1.0 || ^2.0",
"phpunit/phpunit": "^9.5 || ^12.0",
"psalm/plugin-phpunit": "^0.19",
"roave/security-advisories": "dev-latest",
"shipmonk/composer-dependency-analyser": "^1.8",
"sylius-labs/coding-standard": "^4.1.1",
"symplify/easy-coding-standard": "^12.3.6",
"vimeo/psalm": "^6.0"
"symplify/easy-coding-standard": "^12.3.6 || ^13.0.0"
},
"prefer-stable": true,
"autoload": {
Expand All @@ -50,7 +54,8 @@
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": false,
"ergebnis/composer-normalize": true
"ergebnis/composer-normalize": true,
"phpstan/extension-installer": true
},
"sort-packages": true
},
Expand Down
Empty file added phpstan-baseline.neon
Empty file.
23 changes: 23 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
includes:
- phpstan-baseline.neon
- vendor/phpstan/phpstan/conf/bleedingEdge.neon

parameters:
level: 8
paths:
- src
- tests
scanFiles:
- vendor/symfony/dependency-injection/Loader/Configurator/ContainerConfigurator.php
treatPhpDocTypesAsCertain: false
checkInternalClassCaseSensitivity: true
checkMissingVarTagTypehint: true
checkMissingTypehints: true
checkUninitializedProperties: true
featureToggles:
skipCheckGenericClasses:
- Symfony\Component\Form\AbstractType
- Symfony\Component\Form\FormBuilderInterface
- Symfony\Component\Form\FormInterface
- Symfony\Component\Form\FormTypeExtensionInterface
- Symfony\Component\Form\FormTypeInterface
51 changes: 0 additions & 51 deletions psalm.xml

This file was deleted.

6 changes: 3 additions & 3 deletions src/DependencyInjection/SetonoCronExpressionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;

final class SetonoCronExpressionExtension extends Extension implements PrependExtensionInterface
{
#[\Override]
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.xml');
$loader = new PhpFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.php');
}

#[\Override]
Expand Down
14 changes: 7 additions & 7 deletions src/Doctrine/DBAL/Types/CronExpressionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform): ?CronExpr
}

if (!is_string($value)) {
/**
* @psalm-suppress UndefinedMethod
*/
/** @phpstan-ignore staticMethod.notFound */
throw class_exists(InvalidType::class) ? InvalidType::new($value, CronExpression::class, ['string']) : ConversionException::conversionFailedInvalidType($value, CronExpression::class, ['string']);
}

Expand All @@ -47,9 +45,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform): ?CronExpr
try {
return CronExpression::factory($value);
} catch (\Throwable $e) {
/**
* @psalm-suppress UndefinedMethod
*/
/** @phpstan-ignore staticMethod.notFound */
throw class_exists(ValueNotConvertible::class) ? ValueNotConvertible::new($value, CronExpression::class, null, $e) : ConversionException::conversionFailed($value, CronExpression::class, $e);
}
}
Expand All @@ -72,7 +68,11 @@ public function getName(): string
return self::CRON_EXPRESSION_TYPE;
}

/** @noinspection PhpUnusedParameterInspection */
/**
* @noinspection PhpUnusedParameterInspection
*
* @phpstan-ignore return.tooWideBool
*/
public function requiresSQLCommentHint(AbstractPlatform $platform): bool
{
return true;
Expand Down
6 changes: 3 additions & 3 deletions src/Form/DataTransformer/CronExpressionToPartsTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

/**
* @template-implements DataTransformerInterface<CronExpression, array<string, array<string>>>
*
* @psalm-suppress TooManyTemplateParams
*/
final class CronExpressionToPartsTransformer implements DataTransformerInterface
{
Expand Down Expand Up @@ -88,7 +86,9 @@ public function reverseTransform($value): CronExpression
}

/**
* @psalm-assert array<string, array<scalar>> $value
* @phpstan-assert array<string, array<scalar>> $value
*
* @phpstan-ignore missingType.iterableValue
*/
private static function allArrayScalar(array $value): bool
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

/**
* @template-implements DataTransformerInterface<CronExpression, array<string,string>>
*
* @psalm-suppress TooManyTemplateParams
*/
final class CronExpressionToStringPartsTransformer implements DataTransformerInterface
{
Expand Down Expand Up @@ -88,7 +86,9 @@ public function reverseTransform($value): CronExpression
}

/**
* @psalm-assert iterable<string> $value
* @phpstan-assert array<string> $value
*
* @phpstan-ignore missingType.iterableValue
*/
private static function allString(array $value): bool
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

/**
* @template-implements DataTransformerInterface<CronExpression, string>
*
* @psalm-suppress TooManyTemplateParams
*/
final class CronExpressionToStringTransformer implements DataTransformerInterface
{
Expand Down
11 changes: 6 additions & 5 deletions src/Form/Type/CronExpressionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ public function getBlockPrefix(): string
/**
* Will create an array where the first key is 1
* oneIndexedRange(3) will return [1 => 1, 2 => 2, 3 => 3].
*
* @return array<int, int>
*/
private function oneIndexedRange(int $end, int $start = 0): array
{
Expand All @@ -147,11 +149,10 @@ private function oneIndexedRange(int $end, int $start = 0): array

protected function buildCallback(int $payload): Callback
{
// helper function for Symfony 4.4
return new Callback([
'callback' => [$this, 'validateCronField'],
'payload' => $payload,
]);
return new Callback(
callback: $this->validateCronField(...),
payload: $payload,
);
}

public function validateCronField(?string $value, ExecutionContextInterface $context, int $payload): void
Expand Down
16 changes: 6 additions & 10 deletions src/Form/TypeGuesser/CronExpressionTypeGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ private function createExtractor(): PropertyTypeExtractorInterface
], [], [], [$reflectionExtractor]);
}

/**
* @param class-string $class
*/
private function isCronExpression(string $class, string $property): bool
{
/** @phpstan-ignore function.alreadyNarrowedType */
if (class_exists(Type::class) && method_exists($this->extractor, 'getType')) {
/**
* @psalm-suppress MixedAssignment
*/
$type = $this->extractor->getType($class, $property);
if (null === $type) {
return false;
Expand All @@ -104,18 +105,13 @@ private function isCronExpression(string $class, string $property): bool
return true;
}
} else {
/**
* @psalm-suppress DeprecatedClass
* @psalm-suppress DeprecatedMethod
*/
/** @phpstan-ignore method.notFound */
$types = $this->extractor->getTypes($class, $property);
if (null === $types) {
return false;
}
foreach ($types as $lType) {
/**
* @psalm-suppress DeprecatedClass
*/
/** @phpstan-ignore class.notFound */
if (LegacyType::BUILTIN_TYPE_OBJECT === $lType->getBuiltinType() &&
CronExpression::class === $lType->getClassName()) {
return true;
Expand Down
Loading