Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
98 changes: 98 additions & 0 deletions phpstan.baseline-generated-files.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
parameters:
ignoreErrors:
-
message: "#^Result of && is always false\\.$#"
count: 1
path: src/DependencyInjection/ThumbnailService.php
reportUnmatched: false

-
message: "#^Strict comparison using \\=\\=\\= between false and true will always evaluate to false\\.$#"
count: 1
path: src/DependencyInjection/ThumbnailService.php
reportUnmatched: false
-
message: "#^Call to an undefined method Shopware\\\\Core\\\\Content\\\\Media\\\\Message\\\\GenerateThumbnailsMessage\\:\\:setContext\\(\\)\\.$#"
count: 1
path: src/DependencyInjection/FileSaver.php
reportUnmatched: false

-
message: '#^Call to deprecated method#'
path: src/DependencyInjection/FileSaver.php
reportUnmatched: false

-
message: "#^Method Frosh\\\\ThumbnailProcessor\\\\DependencyInjection\\\\ThumbnailService\\:\\:(.*)\\(\\) is unused\\.$#"
path: src/DependencyInjection/ThumbnailService.php
reportUnmatched: false

-
message: "#^Anonymous function should return array but returns mixed.#"
path: src/DependencyInjection/ThumbnailService.php
reportUnmatched: false

-
message: "#tag\\:v6\\.7\\.0 - reason\\:return-type-change - Return type will be native#"
path: src/DependencyInjection/ThumbnailService.php
reportUnmatched: false

-
message: "#^Frosh\\\\ThumbnailProcessor\\\\DependencyInjection\\\\FileSaver::__construct\\(\\) does not call parent constructor from Shopware\\\\Core\\\\Content\\\\Media\\\\File\\\\FileSaver\\.$#"
count: 1
path: src/DependencyInjection/FileSaver.php
reportUnmatched: false

-
message: "#^Only booleans are allowed in a negated boolean, string\\|null given\\.$#"
count: 1
path: src/DependencyInjection/FileSaver.php
reportUnmatched: false

-
message: "#^Call to function is_string\\(\\) with string will always evaluate to true\\.$#"
count: 1
path: src/DependencyInjection/FileSaver.php
reportUnmatched: false

-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 1
path: src/DependencyInjection/FileSaver.php
reportUnmatched: false

-
message: "#^Casting to string something that's already string\\.$#"
count: 1
path: src/DependencyInjection/FileSaver.php
reportUnmatched: false

-
message: "#^Only booleans are allowed in a negated boolean, Shopware\\\\Core\\\\Content\\\\Media\\\\Aggregate\\\\MediaThumbnail\\\\MediaThumbnailCollection\\|null given\\.$#"
count: 1
path: src/DependencyInjection/FileSaver.php
reportUnmatched: false

-
message: "#^Frosh\\\\ThumbnailProcessor\\\\DependencyInjection\\\\ThumbnailService::__construct\\(\\) does not call parent constructor from Shopware\\\\Core\\\\Content\\\\Media\\\\Thumbnail\\\\ThumbnailService\\.$#"
count: 1
path: src/DependencyInjection/ThumbnailService.php
reportUnmatched: false

-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 4
path: src/DependencyInjection/ThumbnailService.php
reportUnmatched: false

-
message: "#^Only booleans are allowed in a negated boolean, Shopware\\\\Core\\\\Content\\\\Media\\\\Aggregate\\\\MediaThumbnail\\\\MediaThumbnailCollection\\|null given\\.$#"
count: 1
path: src/DependencyInjection/ThumbnailService.php
reportUnmatched: false

-
message: "#^Parameter \\#4 \\$metadata of method Frosh\\\\ThumbnailProcessor\\\\DependencyInjection\\\\FileSaver::updateMediaEntity\\(\\) expects array<string, mixed>\\|null, array\\|null given\\.$#"
count: 1
path: src/DependencyInjection/FileSaver.php
reportUnmatched: false
68 changes: 43 additions & 25 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
includes:
- phpstan.baseline-generated-files.neon

parameters:
level: max
paths:
- src
- tests
ignoreErrors:

-
message: "#^Result of && is always false\\.$#"
count: 1
path: src/DependencyInjection/ThumbnailService.php
message: "#Call to static method PHPUnit\\\\Framework\\\\Assert::assertIsIterable\\(\\) with array<int\\|string, string> will always evaluate to true.#"
reportUnmatched: false

-
message: "#^Strict comparison using \\=\\=\\= between false and true will always evaluate to false\\.$#"
count: 1
path: src/DependencyInjection/ThumbnailService.php
message: "#staticMethod.alreadyNarrowedType#"
path: tests/unit/Core/Media/MediaUrlGeneratorTest.php
reportUnmatched: false

-
message: "#tag\\:v6\\.8\\.0 - reason:return-type-change - return type will be nullable#"
path: tests/integration/MediaUrlTest.php
reportUnmatched: false

-
Expand All @@ -38,52 +44,64 @@ parameters:
-
message: "#possible param types, only#"
reportUnmatched: false

-
message: "#^Call to an undefined method Shopware\\\\Core\\\\Content\\\\Media\\\\Message\\\\GenerateThumbnailsMessage\\:\\:setContext\\(\\)\\.$#"
count: 1
path: src/DependencyInjection/FileSaver.php
message: "#(.*?)Shopware\\\\Tests\\\\Unit\\\\Common\\\\Stubs\\\\SystemConfigService\\\\StaticSystemConfigService#"
reportUnmatched: false

-
message: "#^Method Frosh\\\\ThumbnailProcessor\\\\DependencyInjection\\\\ThumbnailService\\:\\:(.*)\\(\\) is unused\\.$#"
path: src/DependencyInjection/ThumbnailService.php
message: "#(.*?)Shopware\\\\Tests\\\\Unit\\\\Common\\\\Stubs\\\\DataAbstractionLayer\\\\StaticEntityRepository#"
reportUnmatched: false

-
message: "#^Anonymous function should return array but returns mixed.#"
path: src/DependencyInjection/ThumbnailService.php
message: '#.* generic class Shopware\\Core\\Framework\\DataAbstractionLayer\\EntityRepository.*not specify its types: TEntityCollection#'
reportUnmatched: false

-
message: "#tag\\:v6\\.7\\.0 - reason\\:return-type-change - Return type will be native#"
path: src/DependencyInjection/ThumbnailService.php
reportUnmatched: false
message: "#^Parameter \\#1 \\$objectOrClass of class ReflectionClass constructor expects class\\-string\\<T of object\\>\\|T of object, string given\\.$#"
count: 1
path: src/DependencyInjection/GeneratorCompilerPass.php

-
message: "#^Property Frosh\\\\ThumbnailProcessor\\\\Tests\\\\Integration\\\\MediaUrlTest.*does not accept object.*#"
path: tests/integration/MediaUrlTest.php

-
message: '#^Call to deprecated method#'
path: src/DependencyInjection/FileSaver.php
message: "#Use AbstractMediaUrlGenerator instead#"
reportUnmatched: false

-
message: "#(.*?)Shopware\\\\Tests\\\\Unit\\\\Common\\\\Stubs\\\\SystemConfigService\\\\StaticSystemConfigService#"
message: "#^Strict comparison using === between array<PhpParser\\\\Node\\\\Stmt> and null will always evaluate to false\\.$#"
count: 1
path: src/DependencyInjection/GeneratorCompilerPass.php
reportUnmatched: false

-
message: "#(.*?)Shopware\\\\Tests\\\\Unit\\\\Common\\\\Stubs\\\\DataAbstractionLayer\\\\StaticEntityRepository#"
message: "#^Call to function method_exists\\(\\) with 'PhpParser\\\\\\\\ParserFactory' and 'createForHostVersion' will always evaluate to true\\.$#"
count: 1
path: src/DependencyInjection/GeneratorCompilerPass.php
reportUnmatched: false

-
message: '#.* generic class Shopware\\Core\\Framework\\DataAbstractionLayer\\EntityRepository.*not specify its types: TEntityCollection#'
message: "#^Access to undefined constant PhpParser\\\\ParserFactory::ONLY_PHP7\\.$#"
count: 1
path: src/DependencyInjection/GeneratorCompilerPass.php
reportUnmatched: false

-
message: "#^Parameter \\#1 \\$objectOrClass of class ReflectionClass constructor expects class\\-string\\<T of object\\>\\|T of object, string given\\.$#"
message: "#^Call to an undefined method PhpParser\\\\ParserFactory::create\\(\\)\\.$#"
count: 1
path: src/DependencyInjection/GeneratorCompilerPass.php
reportUnmatched: false

-
message: "#^Property Frosh\\\\ThumbnailProcessor\\\\Tests\\\\Integration\\\\MediaUrlTest.*does not accept object.*#"
path: tests/integration/MediaUrlTest.php
message: "#^Method Frosh\\\\ThumbnailProcessor\\\\DependencyInjection\\\\GeneratorCompilerPass::getPhpParser\\(\\) should return PhpParser\\\\Parser but returns mixed\\.$#"
count: 1
path: src/DependencyInjection/GeneratorCompilerPass.php
reportUnmatched: false

-
message: "#Use AbstractMediaUrlGenerator instead#"
message: "#^Property PhpParser\\\\Node\\\\Stmt\\\\Namespace_::\\$stmts \\(array<PhpParser\\\\Node\\\\Stmt>\\) does not accept array<PhpParser\\\\Node\\\\Stmt>\\|null\\.$#"
count: 1
path: src/DependencyInjection/GeneratorCompilerPass.php
reportUnmatched: false
12 changes: 6 additions & 6 deletions src/Controller/Api/TestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ private function getProductFolderId(Context $context): string
->addAssociation('defaultFolder')
->setLimit(1);

$ids = $this->mediaFolderRepository
$id = $this->mediaFolderRepository
->searchIds($criteria, $context)
->getIds();
->getIds()[0] ?? null;

if (!empty($ids[0]) && \is_string($ids[0])) {
return $ids[0];
if (\is_string($id)) {
return $id;
}

throw new \RuntimeException('Media folder for product could not have been found!');
Expand All @@ -100,7 +100,7 @@ private function getSampleMedia(string $testFile): MediaEntity
$pathInfo = pathinfo($testFile);

$existingMedia = $this->getMediaById($pathInfo['filename'], $context);
if ($existingMedia) {
if ($existingMedia !== null) {
return $existingMedia;
}

Expand Down Expand Up @@ -130,7 +130,7 @@ private function getSampleMedia(string $testFile): MediaEntity
);

$existingMedia = $this->getMediaById($pathInfo['filename'], $context);
if ($existingMedia) {
if ($existingMedia !== null) {
return $existingMedia;
}

Expand Down
8 changes: 4 additions & 4 deletions src/Core/Media/MediaUrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public function generate(array $paths): array
private function canProcess(string $path): bool
{
$fileExtension = \pathinfo($path, \PATHINFO_EXTENSION);
\assert(\is_string($fileExtension));

return $this->canProcessFileExtension($fileExtension);
}
Expand All @@ -71,7 +70,7 @@ private function canProcessFileExtension(string $fileExtension): bool
{
$extensionsAllowList = $this->getExtensionsAllowList();

if (empty($extensionsAllowList)) {
if ($extensionsAllowList === []) {
return false;
}

Expand Down Expand Up @@ -101,7 +100,8 @@ private function getExtensionsAllowList(): array
\explode(
',',
(string) \preg_replace('/\s+/', '', \strtolower($extensionsAllowListConfig))
)
),
static fn($value) => $value !== ''
)
);
}
Expand All @@ -111,7 +111,7 @@ private function getExtensionsAllowList(): array

private function getWidth(string $maxWidth, UrlParams $value): string
{
if ($value instanceof ExtendedUrlParams && !empty($value->width)) {
if ($value instanceof ExtendedUrlParams && $value->width !== null && $value->width !== 0) {
return (string) $value->width;
}

Expand Down
8 changes: 4 additions & 4 deletions src/Core/Media/MediaUrlLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function loaded(iterable $entities): void
{
$mapping = $this->map($entities);

if (empty($mapping)) {
if ($mapping === []) {
return;
}

Expand Down Expand Up @@ -65,12 +65,12 @@ private function map(iterable $entities): array
$mapped = [];

foreach ($entities as $entity) {
if (!$entity->has('path') || empty($entity->get('path'))) {
if (!$entity->has('path') || $entity->get('path') === null || $entity->get('path') === '') {
continue;
}

// don't generate private urls
if (!$entity->has('private') || $entity->get('private')) {
if (!$entity->has('private') || $entity->get('private') === true) {
continue;
}

Expand All @@ -91,7 +91,7 @@ private function map(iterable $entities): array
continue;
}

if (!$thumbnail->has('path') || empty($thumbnail->get('path'))) {
if (!$thumbnail->has('path') || $thumbnail->get('path') === null || $thumbnail->get('path') === '') {
continue;
}

Expand Down
22 changes: 14 additions & 8 deletions src/DependencyInjection/GeneratorCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function process(ContainerBuilder $container): void
{
$fileContents = $this->getFileContent();

if (empty($fileContents)) {
if ($fileContents === null || $fileContents === '') {
$this->removeReflectionClass();

return;
Expand Down Expand Up @@ -71,7 +71,7 @@ public function process(ContainerBuilder $container): void
$doc = '/**' . \PHP_EOL . 'THIS CLASS HAS BEEN GENERATED AUTOMATICALLY' . \PHP_EOL . '*/';

$existingDocs = $class->getDocComment()?->getText() ?? '';
if (!empty($existingDocs)) {
if ($existingDocs !== '') {
$doc .= \PHP_EOL . $existingDocs;
}

Expand Down Expand Up @@ -123,7 +123,7 @@ private function handleThumbnailService(NodeFinder $nodeFinder, array $ast): voi
$updateThumbnailsNode = $this->getClassMethod($nodeFinder, 'updateThumbnails', $ast);

$stmts = $updateThumbnailsNode->getStmts();
if (empty($stmts)) {
if ($stmts === null || $stmts === []) {
throw new \RuntimeException(\sprintf('Method %s in class %s is empty', 'updateThumbnails', $this->class));
}

Expand Down Expand Up @@ -174,7 +174,7 @@ private function addUsesOfNamespace(?array &$stmts, string $namespace): void
$filePath = $this->getFileName();
$files = glob(\dirname($filePath) . '/*.php');

if (empty($files)) {
if ($files === false || $files === []) {
return;
}

Expand All @@ -188,7 +188,7 @@ private function addUsesOfNamespace(?array &$stmts, string $namespace): void
$uses[] = new UseUse(new Name($class));
}

if (empty($uses)) {
if ($uses === []) {
return;
}

Expand All @@ -197,7 +197,13 @@ private function addUsesOfNamespace(?array &$stmts, string $namespace): void

private function getFileContent(): ?string
{
return file_get_contents($this->getFileName()) ?: null;
$content = file_get_contents($this->getFileName());

if (\is_string($content)) {
return $content;
}

return null;
}

private function getFileName(): string
Expand All @@ -206,7 +212,7 @@ private function getFileName(): string

$fileName = $reflectionClass->getFileName();

if (empty($fileName)) {
if ($fileName === false) {
throw new \RuntimeException(\sprintf('Cannot get fileName of class %s', $this->class));
}

Expand All @@ -231,7 +237,7 @@ private function getClassName(): string
{
$lastOccur = strrchr($this->class, '\\');

if (empty($lastOccur)) {
if ($lastOccur === false || $lastOccur === '') {
throw new \RuntimeException(\sprintf('Cannot determine className from %s', $this->class));
}

Expand Down
Loading