Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI] Added phpstan with baseline & fixed some issues #55

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ jobs:
- name: Run test suite
run: composer run-script --timeout=600 test

- name: Run PHPStan analysis
run: composer run-script phpstan

integration-tests:
name: Tests
needs: tests
Expand Down
9 changes: 7 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"php": "^7.4 || ^8.0",
"ext-libxml": "*",
"ext-simplexml": "*",
"ext-json": "*",
"ibexa/core": "~4.6.0@dev",
"ibexa/content-forms": "~4.6.0@dev",
"ibexa/graphql": "~4.6.0@dev",
Expand All @@ -48,13 +49,17 @@
"ibexa/design-engine": "~4.6.0@dev",
"ibexa/code-style": "^1.0",
"friendsofphp/php-cs-fixer": "^3.0",
"phpunit/phpunit": "^9.5"
"phpunit/phpunit": "^9.5",
"phpstan/phpstan": "^1.10",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can actually go and install v2 immediately. It's something we probably want to do with other packages too either.

"phpstan/phpstan-phpunit": "^1.3",
"phpstan/phpstan-symfony": "^1.3"
},
"scripts": {
"fix-cs": "php-cs-fixer fix --config=.php-cs-fixer.php -v --show-progress=dots",
"check-cs": "@fix-cs --dry-run",
"test": "phpunit -c phpunit.xml",
"test-integration": "phpunit -c phpunit.integration.xml"
"test-integration": "phpunit -c phpunit.integration.xml",
"phpstan": "phpstan analyse"
},
"extra": {
"branch-alias": {
Expand Down
156 changes: 156 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
parameters:
ignoreErrors:
-
message: "#^Cannot access offset 'entries' on array\\|bool\\|float\\|int\\|string\\|null\\.$#"
count: 1
path: src/bundle/Command/MigrateLegacyMatrixCommand.php

-
message: "#^Cannot call method fetchAll\\(\\) on Doctrine\\\\DBAL\\\\ForwardCompatibility\\\\Result\\|int\\|string\\.$#"
count: 2
path: src/bundle/Command/MigrateLegacyMatrixCommand.php

-
message: "#^Cannot call method fetchColumn\\(\\) on Doctrine\\\\DBAL\\\\ForwardCompatibility\\\\Result\\|int\\|string\\.$#"
count: 1
path: src/bundle/Command/MigrateLegacyMatrixCommand.php

-
message: "#^Method Ibexa\\\\Bundle\\\\FieldTypeMatrix\\\\Command\\\\MigrateLegacyMatrixCommand\\:\\:configure\\(\\) has no return type specified\\.$#"
count: 1
path: src/bundle/Command/MigrateLegacyMatrixCommand.php

-
message: "#^Method Ibexa\\\\Bundle\\\\FieldTypeMatrix\\\\Command\\\\MigrateLegacyMatrixCommand\\:\\:convertCellsToRows\\(\\) has parameter \\$cells with no value type specified in iterable type array\\.$#"
count: 1
path: src/bundle/Command/MigrateLegacyMatrixCommand.php

-
message: "#^Method Ibexa\\\\Bundle\\\\FieldTypeMatrix\\\\Command\\\\MigrateLegacyMatrixCommand\\:\\:convertCellsToRows\\(\\) has parameter \\$columns with no value type specified in iterable type array\\.$#"
count: 1
path: src/bundle/Command/MigrateLegacyMatrixCommand.php

-
message: "#^Method Ibexa\\\\Bundle\\\\FieldTypeMatrix\\\\Command\\\\MigrateLegacyMatrixCommand\\:\\:convertCellsToRows\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/bundle/Command/MigrateLegacyMatrixCommand.php

-
message: "#^Method Ibexa\\\\Bundle\\\\FieldTypeMatrix\\\\Command\\\\MigrateLegacyMatrixCommand\\:\\:getContentClassAttributes\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/bundle/Command/MigrateLegacyMatrixCommand.php

-
message: "#^Method Ibexa\\\\Bundle\\\\FieldTypeMatrix\\\\Command\\\\MigrateLegacyMatrixCommand\\:\\:getContentObjectAttributes\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/bundle/Command/MigrateLegacyMatrixCommand.php

-
message: "#^Variable \\$xml might not be defined\\.$#"
count: 1
path: src/bundle/Command/MigrateLegacyMatrixCommand.php

-
message: "#^Parameter \\#1 \\$input of static method Symfony\\\\Component\\\\Yaml\\\\Yaml\\:\\:parse\\(\\) expects string, string\\|false given\\.$#"
count: 1
path: src/bundle/DependencyInjection/IbexaFieldTypeMatrixExtension.php

-
message: "#^Property Ibexa\\\\Core\\\\Persistence\\\\Legacy\\\\Content\\\\StorageFieldDefinition\\:\\:\\$dataText5 \\(string\\) on left side of \\?\\? is not nullable\\.$#"
count: 1
path: src/lib/FieldType/Converter/MatrixConverter.php

-
message: "#^Method Ibexa\\\\FieldTypeMatrix\\\\FieldType\\\\Value\\\\Row\\:\\:__construct\\(\\) has parameter \\$cells with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/FieldType/Value/Row.php

-
message: "#^Method Ibexa\\\\FieldTypeMatrix\\\\FieldType\\\\Value\\\\Row\\:\\:__get\\(\\) has no return type specified\\.$#"
count: 1
path: src/lib/FieldType/Value/Row.php

-
message: "#^Method Ibexa\\\\FieldTypeMatrix\\\\FieldType\\\\Value\\\\Row\\:\\:__get\\(\\) has parameter \\$name with no type specified\\.$#"
count: 1
path: src/lib/FieldType/Value/Row.php

-
message: "#^Method Ibexa\\\\FieldTypeMatrix\\\\FieldType\\\\Value\\\\Row\\:\\:__isset\\(\\) has parameter \\$name with no type specified\\.$#"
count: 1
path: src/lib/FieldType/Value/Row.php

-
message: "#^Method Ibexa\\\\FieldTypeMatrix\\\\FieldType\\\\Value\\\\Row\\:\\:getCells\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/FieldType/Value/Row.php

-
message: "#^Parameter \\#2 \\$callback of function array_filter expects \\(callable\\(string\\)\\: bool\\)\\|null, 'strlen' given\\.$#"
count: 1
path: src/lib/FieldType/Value/Row.php

-
message: "#^Property Ibexa\\\\FieldTypeMatrix\\\\FieldType\\\\Value\\\\Row\\:\\:\\$cells type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/FieldType/Value/Row.php

-
message: "#^Method Ibexa\\\\FieldTypeMatrix\\\\GraphQL\\\\InputHandler\\:\\:toFieldValue\\(\\) has parameter \\$input with no type specified\\.$#"
count: 1
path: src/lib/GraphQL/InputHandler.php

-
message: "#^Method Ibexa\\\\FieldTypeMatrix\\\\GraphQL\\\\InputHandler\\:\\:toFieldValue\\(\\) has parameter \\$inputFormat with no type specified\\.$#"
count: 1
path: src/lib/GraphQL/InputHandler.php

-
message: "#^Method Ibexa\\\\FieldTypeMatrix\\\\GraphQL\\\\Schema\\\\MatrixFieldDefinitionInputSchemaWorker\\:\\:canWork\\(\\) has parameter \\$args with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/GraphQL/Schema/MatrixFieldDefinitionInputSchemaWorker.php

-
message: "#^Method Ibexa\\\\FieldTypeMatrix\\\\GraphQL\\\\Schema\\\\MatrixFieldDefinitionInputSchemaWorker\\:\\:typeName\\(\\) has parameter \\$args with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/GraphQL/Schema/MatrixFieldDefinitionInputSchemaWorker.php

-
message: "#^Method Ibexa\\\\FieldTypeMatrix\\\\GraphQL\\\\Schema\\\\MatrixFieldDefinitionInputSchemaWorker\\:\\:work\\(\\) has parameter \\$args with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/GraphQL/Schema/MatrixFieldDefinitionInputSchemaWorker.php

-
message: "#^Method Ibexa\\\\FieldTypeMatrix\\\\GraphQL\\\\Schema\\\\MatrixFieldDefinitionSchemaWorker\\:\\:canWork\\(\\) has parameter \\$args with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/GraphQL/Schema/MatrixFieldDefinitionSchemaWorker.php

-
message: "#^Method Ibexa\\\\FieldTypeMatrix\\\\GraphQL\\\\Schema\\\\MatrixFieldDefinitionSchemaWorker\\:\\:typeName\\(\\) has parameter \\$args with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/GraphQL/Schema/MatrixFieldDefinitionSchemaWorker.php

-
message: "#^Method Ibexa\\\\FieldTypeMatrix\\\\GraphQL\\\\Schema\\\\MatrixFieldDefinitionSchemaWorker\\:\\:work\\(\\) has parameter \\$args with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/GraphQL/Schema/MatrixFieldDefinitionSchemaWorker.php

-
message: "#^Method Ibexa\\\\FieldTypeMatrix\\\\GraphQL\\\\SilentRow\\:\\:__get\\(\\) has no return type specified\\.$#"
count: 1
path: src/lib/GraphQL/SilentRow.php

-
message: "#^Method Ibexa\\\\FieldTypeMatrix\\\\GraphQL\\\\SilentRow\\:\\:__get\\(\\) has parameter \\$name with no type specified\\.$#"
count: 1
path: src/lib/GraphQL/SilentRow.php

-
message: "#^Static property Ibexa\\\\Contracts\\\\Core\\\\Test\\\\Repository\\\\SetupFactory\\\\Legacy\\:\\:\\$serviceContainer \\(Ibexa\\\\Core\\\\Base\\\\ServiceContainer\\) in isset\\(\\) is not nullable\\.$#"
count: 1
path: tests/lib/LegacySetupFactory.php

-
message: "#^Access to an undefined property Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\ValueObject\\:\\:\\$id\\.$#"
count: 1
path: tests/lib/Repository/SearchServiceTest.php
10 changes: 10 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
includes:
- phpstan-baseline.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-symfony/extension.neon

parameters:
level: 8
paths:
- src
- tests
25 changes: 4 additions & 21 deletions src/bundle/DependencyInjection/IbexaFieldTypeMatrixExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@

class IbexaFieldTypeMatrixExtension extends Extension implements PrependExtensionInterface
{
/**
* Loads a specific configuration.
*
* @param array $configs
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new YamlFileLoader(
$container,
Expand All @@ -35,32 +29,21 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('services.yaml');
}

/**
* Allow an extension to prepend the extension configurations.
*
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
*/
public function prepend(ContainerBuilder $container)
public function prepend(ContainerBuilder $container): void
{
$this->prependKernelSettings($container);
$this->prependJMSTranslation($container);
$this->prependGraphQL($container);
}

/**
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
*/
public function prependKernelSettings(ContainerBuilder $container)
public function prependKernelSettings(ContainerBuilder $container): void
{
$configFile = __DIR__ . '/../Resources/config/kernel.yaml';
$config = Yaml::parse(file_get_contents($configFile));
$container->prependExtensionConfig('ibexa', $config);
$container->addResource(new FileResource($configFile));
}

/**
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
*/
public function prependJMSTranslation(ContainerBuilder $container): void
{
$container->prependExtensionConfig('jms_translation', [
Expand All @@ -78,7 +61,7 @@ public function prependJMSTranslation(ContainerBuilder $container): void
]);
}

private function prependGraphQL(ContainerBuilder $container)
private function prependGraphQL(ContainerBuilder $container): void
{
$container->prependExtensionConfig('overblog_graphql', [
'definitions' => [
Expand Down
4 changes: 2 additions & 2 deletions src/lib/FieldType/Converter/MatrixConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function toStorageValue(FieldValue $value, StorageFieldValue $storageFiel
{
$entries = $value->data['entries'] ?? [];

$storageFieldValue->dataText = json_encode(array_values($entries));
$storageFieldValue->dataText = json_encode(array_values($entries)) ?: '';
}

/**
Expand Down Expand Up @@ -67,7 +67,7 @@ public function toStorageFieldDefinition(FieldDefinition $fieldDef, StorageField
});

$storageDef->dataInt1 = $minimumRows;
$storageDef->dataText5 = json_encode($columns);
$storageDef->dataText5 = json_encode($columns) ?: '';
}

/**
Expand Down
9 changes: 4 additions & 5 deletions src/lib/FieldType/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ public function getName(SPIValue $value, FieldDefinition $fieldDefinition, strin
*/
public function getEmptyValue(): SPIValue
{
$value = new Value([]);

return $value;
return new Value([]);
}

/**
Expand All @@ -147,7 +145,7 @@ public function fromHash($hash): SPIValue
/**
* {@inheritdoc}
*/
protected function checkValueStructure(FieldTypeValue $value)
protected function checkValueStructure(FieldTypeValue $value): void
{
// Value is self-contained and strong typed
return;
Expand All @@ -164,6 +162,8 @@ public function isEmptyValue(SPIValue $value): bool

/**
* {@inheritdoc}
*
* @param \Ibexa\FieldTypeMatrix\FieldType\Value $value
*/
public function validate(FieldDefinition $fieldDefinition, SPIValue $value)
{
Expand All @@ -173,7 +173,6 @@ public function validate(FieldDefinition $fieldDefinition, SPIValue $value)

$countNonEmptyRows = 0;

/** @var \Ibexa\FieldTypeMatrix\FieldType\Value $value */
foreach ($value->getRows() as $row) {
if (!$row->isEmpty()) {
++$countNonEmptyRows;
Expand Down
16 changes: 2 additions & 14 deletions src/lib/FieldType/Value.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,26 @@

class Value extends BaseValue
{
/** @var \Ibexa\FieldTypeMatrix\FieldType\Value\RowsCollection */
protected $rows;
protected RowsCollection $rows;

/**
* @param array $rows
* @param \Ibexa\FieldTypeMatrix\FieldType\Value\Row[] $rows
*/
public function __construct(array $rows = [])
{
$this->rows = new RowsCollection($rows);
}

/**
* @return \Ibexa\FieldTypeMatrix\FieldType\Value\RowsCollection
*/
public function getRows(): RowsCollection
{
return $this->rows;
}

/**
* @param \Ibexa\FieldTypeMatrix\FieldType\Value\RowsCollection $rows
*/
public function setRows(RowsCollection $rows): void
{
$this->rows = $rows;
}

/**
* Returns a string representation of the field value.
*
* @return string
*/
public function __toString(): string
{
return '';
Expand Down
Loading
Loading