Skip to content

Commit

Permalink
[Task] Bump phpstan version (pimcore#14571)
Browse files Browse the repository at this point in the history
* Bump phpstan version to 1.10.5

* Fixing phpstan errors excecpt unused methods

* Fixing phpstan errors excecpt unused methods

* Fix typo for unused method

* Remove unused method, add Messenger/Handler to ignoreErrors

* Fixed typo

* Adding null to docs for redirects
  • Loading branch information
mattamon authored Mar 22, 2023
1 parent 765832f commit 64e3a09
Show file tree
Hide file tree
Showing 19 changed files with 73 additions and 115 deletions.
15 changes: 7 additions & 8 deletions bundles/AdminBundle/Controller/Admin/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,17 +404,16 @@ public function getSystemAction(Request $request, Config $config)
$valueArray['general']['valid_language'] = explode(',', $valueArray['general']['valid_languages']);

//for "wrong" legacy values
if (is_array($valueArray['general']['valid_language'])) {
foreach ($valueArray['general']['valid_language'] as $existingValue) {
if (!in_array($existingValue, $validLanguages)) {
$languageOptions[] = [
'language' => $existingValue,
'display' => $existingValue,
];
}
foreach ($valueArray['general']['valid_language'] as $existingValue) {
if (!in_array($existingValue, $validLanguages)) {
$languageOptions[] = [
'language' => $existingValue,
'display' => $existingValue,
];
}
}


$response = [
'values' => $valueArray,
'config' => [
Expand Down
4 changes: 2 additions & 2 deletions bundles/CoreBundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2137,7 +2137,7 @@ private function addPredefinedPropertiesNode(ArrayNodeDefinition $rootNode)
*
* @param ArrayNodeDefinition $rootNode
*/
private function addStaticroutesNode(ArrayNodeDefinition $rootNode)
private function addStaticRoutesNode(ArrayNodeDefinition $rootNode)
{
$rootNode
->children()
Expand Down Expand Up @@ -2297,7 +2297,7 @@ private function addTemplatingEngineNode(ArrayNodeDefinition $rootNode): void
->addDefaultsIfNotSet()
->children()
->arrayNode('sandbox_security_policy')
->info('Whitelist tags, filters & functions for evaluating twig
->info('Whitelist tags, filters & functions for evaluating twig
templates in a sandbox environment e.g. used by Mailer & Text layout component.')
->children()
->arrayNode('tags')
Expand Down
19 changes: 0 additions & 19 deletions bundles/CoreBundle/DependencyInjection/PimcoreCoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,25 +315,6 @@ private function configureTargeting(ContainerBuilder $container, LoaderInterface
->setArgument('$actionHandlers', $actionHandlerLocator);
}

/**
* Configures a "typed locator" (a class exposing get/has for a specific type) wrapping
* a standard service locator. Example: Pimcore\Targeting\DataProviderLocator
*
* @param ContainerBuilder $container
* @param string $locatorClass
* @param array $services
*/
private function configureTypedLocator(ContainerBuilder $container, string $locatorClass, array $services)
{
$serviceLocator = new Definition(ServiceLocator::class, [$services]);
$serviceLocator
->setPublic(false)
->addTag('container.service_locator');

$locator = $container->getDefinition($locatorClass);
$locator->setArgument('$locator', $serviceLocator);
}

/**
* Handle pimcore.security.encoder_factories mapping
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ abstract class CachingPriceSystem extends AbstractPriceSystem implements Caching
public function getPriceInfo(CheckoutableInterface $product, $quantityScale = 1, $products = null): PriceInfoInterface
{
$pId = $product->getId();
if (!array_key_exists($pId, $this->priceInfos) || !is_array($this->priceInfos[$pId])) {
if (!array_key_exists($pId, $this->priceInfos)) {
$this->priceInfos[$pId] = [];
}

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
"codeception/codeception": "^4.1.12",
"codeception/module-symfony": "^1.6.0",
"codeception/phpunit-wrapper": "^9",
"phpstan/phpstan": "1.9.17",
"phpstan/phpstan": "1.10.5",
"phpstan/phpstan-symfony": "^1.2.19",
"phpunit/phpunit": "^9.3",
"spiritix/php-chrome-html2pdf": "^1.6",
Expand Down
2 changes: 1 addition & 1 deletion lib/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,6 @@ public function __toString()
return '';
}

return is_string($this->data) ? (string)$this->data : json_encode($this->data, JSON_PRETTY_PRINT);
return json_encode($this->data, JSON_PRETTY_PRINT);
}
}
8 changes: 4 additions & 4 deletions lib/DataObject/ClassBuilder/ClassBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ public function buildClass(ClassDefinition $classDefinition): string

$cd .= "\n\n";

if (is_array($classDefinition->getFieldDefinitions()) && count($classDefinition->getFieldDefinitions())) {
foreach ($classDefinition->getFieldDefinitions() as $def) {
$cd .= $this->fieldDefinitionBuilder->buildFieldDefinition($classDefinition, $def);
}

foreach ($classDefinition->getFieldDefinitions() as $def) {
$cd .= $this->fieldDefinitionBuilder->buildFieldDefinition($classDefinition, $def);
}


$cd .= "}\n";
$cd .= "\n";

Expand Down
8 changes: 4 additions & 4 deletions lib/DataObject/ClassBuilder/FieldCollectionClassBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ public function buildClass(Definition $definition): string

$cd .= 'protected $type = "' . $definition->getKey() . "\";\n";

if (is_array($definition->getFieldDefinitions()) && count($definition->getFieldDefinitions())) {
foreach ($definition->getFieldDefinitions() as $key => $def) {
$cd .= 'protected $' . $key . ";\n";
}

foreach ($definition->getFieldDefinitions() as $key => $def) {
$cd .= 'protected $' . $key . ";\n";
}


$cd .= "\n\n";

$fdDefs = $definition->getFieldDefinitions();
Expand Down
28 changes: 14 additions & 14 deletions lib/DataObject/ClassBuilder/ObjectBrickClassBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ public function buildClass(Definition $definition): string

$cd .= 'protected $type = "' . $definition->getKey() . "\";\n";

if (is_array($definition->getFieldDefinitions()) && count($definition->getFieldDefinitions())) {
foreach ($definition->getFieldDefinitions() as $key => $def) {
$cd .= 'protected $' . $key . ";\n";
}

foreach ($definition->getFieldDefinitions() as $key => $def) {
$cd .= 'protected $' . $key . ";\n";
}


$cd .= "\n\n";

$cd .= '/**' ."\n";
Expand All @@ -87,22 +87,22 @@ public function buildClass(Definition $definition): string

$cd .= "\n\n";

if (is_array($definition->getFieldDefinitions()) && count($definition->getFieldDefinitions())) {
foreach ($definition->getFieldDefinitions() as $key => $def) {
$cd .= $def->getGetterCodeObjectbrick($definition);

if ($def instanceof ClassDefinition\Data\Localizedfields) {
$cd .= $def->getGetterCode($definition);
}
foreach ($definition->getFieldDefinitions() as $def) {
$cd .= $def->getGetterCodeObjectbrick($definition);

$cd .= $def->getSetterCodeObjectbrick($definition);
if ($def instanceof ClassDefinition\Data\Localizedfields) {
$cd .= $def->getGetterCode($definition);
}

$cd .= $def->getSetterCodeObjectbrick($definition);

if ($def instanceof ClassDefinition\Data\Localizedfields) {
$cd .= $def->getSetterCode($definition);
}
if ($def instanceof ClassDefinition\Data\Localizedfields) {
$cd .= $def->getSetterCode($definition);
}
}


$cd .= "}\n";
$cd .= "\n";

Expand Down
2 changes: 1 addition & 1 deletion lib/Log/ApplicationLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function setRelatedObject($relatedObject)
*/
public function log($level, $message, array $context = [])// : void
{
if (!isset($context['component']) || is_null($context['component'])) {
if (!isset($context['component'])) {
$context['component'] = $this->component;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Maintenance/Tasks/VersionsCleanupTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private function doVersionCleanup()
}
$value = $tConf['steps'] ?? 10;

if (isset($tConf['days']) && !is_null($tConf['days'])) {
if (isset($tConf['days'])) {
$versioningType = 'days';
$value = (int)$tConf['days'];
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Routing/RedirectHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ final class RedirectHandler implements LoggerAwareInterface
private $siteResolver;

/**
* @var Redirect[]
* @var null|Redirect[]
*/
private $redirects;

Expand Down Expand Up @@ -261,7 +261,7 @@ protected function buildRedirectResponse(Redirect $redirect, Request $request, $
*/
private function getRegexRedirects()
{
if (null !== $this->redirects && is_array($this->redirects)) {
if (is_array($this->redirects)) {
return $this->redirects;
}

Expand Down
10 changes: 5 additions & 5 deletions lib/Workflow/SupportStrategy/ExpressionSupportStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ private function supportsClass($subject)
return $subject instanceof $this->className;
}

if (is_array($this->className)) {
foreach ($this->className as $className) {
if ($subject instanceof $className) {
return true;
}

foreach ($this->className as $className) {
if ($subject instanceof $className) {
return true;
}
}


return false;
}

Expand Down
10 changes: 5 additions & 5 deletions models/DataObject/ClassDefinition/Data/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -665,13 +665,13 @@ public function getFieldDefinitions($context = [])
}

$enrichedFieldDefinitions = [];
if (is_array($this->fieldDefinitionsCache)) {
foreach ($this->fieldDefinitionsCache as $key => $fieldDefinition) {
$fieldDefinition = $this->doEnrichFieldDefinition($fieldDefinition, $context);
$enrichedFieldDefinitions[$key] = $fieldDefinition;
}

foreach ($this->fieldDefinitionsCache ?? [] as $key => $fieldDefinition) {
$fieldDefinition = $this->doEnrichFieldDefinition($fieldDefinition, $context);
$enrichedFieldDefinitions[$key] = $fieldDefinition;
}


return $enrichedFieldDefinitions;
}

Expand Down
10 changes: 5 additions & 5 deletions models/DataObject/ClassDefinition/Data/Localizedfields.php
Original file line number Diff line number Diff line change
Expand Up @@ -707,13 +707,13 @@ public function getFieldDefinitions($context = [])
}

$enrichedFieldDefinitions = [];
if (is_array($this->fieldDefinitionsCache)) {
foreach ($this->fieldDefinitionsCache as $key => $fieldDefinition) {
$fieldDefinition = $this->doEnrichFieldDefinition($fieldDefinition, $context);
$enrichedFieldDefinitions[$key] = $fieldDefinition;
}

foreach ($this->fieldDefinitionsCache ?? [] as $key => $fieldDefinition) {
$fieldDefinition = $this->doEnrichFieldDefinition($fieldDefinition, $context);
$enrichedFieldDefinitions[$key] = $fieldDefinition;
}


return $enrichedFieldDefinitions;
}

Expand Down
33 changes: 0 additions & 33 deletions models/Document/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,39 +94,6 @@ public static function render(Document\PageSnippet $document, array $attributes
return $content;
}

/**
* Save document and all child documents
*
* @param Document $document
* @param int $collectGarbageAfterIteration
* @param int $saved
*
* @throws \Exception
*/
private static function saveRecursive($document, $collectGarbageAfterIteration = 25, &$saved = 0)
{
if ($document instanceof Document) {
$document->save();
$saved++;
if ($saved % $collectGarbageAfterIteration === 0) {
\Pimcore::collectGarbage();
}
}

foreach ($document->getChildren() as $child) {
if (!$child->hasChildren()) {
$child->save();
$saved++;
if ($saved % $collectGarbageAfterIteration === 0) {
\Pimcore::collectGarbage();
}
}
if ($child->hasChildren()) {
self::saveRecursive($child, $collectGarbageAfterIteration, $saved);
}
}
}

/**
* @param Document $target
* @param Document $source
Expand Down
8 changes: 0 additions & 8 deletions models/Staticroute.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,6 @@ public function setSiteId($siteId)
*/
public function getSiteId()
{
if ($this->siteId && !is_array($this->siteId)) {
$this->siteId = explode(',', $this->siteId);
}

return $this->siteId;
}

Expand Down Expand Up @@ -603,10 +599,6 @@ public function match($path, $params = [])
*/
public function getMethods()
{
if ($this->methods && is_string($this->methods)) {
$this->methods = explode(',', $this->methods);
}

return $this->methods;
}

Expand Down
2 changes: 1 addition & 1 deletion models/Version/Dao.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function maintenanceGetOutdatedVersions($elementTypes, $ignoreIds = [])
$count = 0;
$stop = false;
foreach ($elementTypes as $elementType) {
if (isset($elementType['days']) && !is_null($elementType['days'])) {
if (isset($elementType['days'])) {
// by days
$deadline = time() - ($elementType['days'] * 86400);
$tmpVersionIds = $this->db->fetchFirstColumn('SELECT id FROM versions as a WHERE (ctype = ? AND date < ?) AND NOT public AND id NOT IN (' . $ignoreIdsList . ')', [$elementType['elementType'], $deadline]);
Expand Down
19 changes: 19 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,22 @@ parameters:
count: 1
path: models/Element/Service.php

-
message: "#^Method Pimcore\\\\Messenger\\\\Handler\\\\CleanupThumbnailsHandler\\:\\:process\\(\\) is unused\\.$#"
count: 1
path: lib/Messenger/Handler/CleanupThumbnailsHandler.php

-
message: "#^Method Pimcore\\\\Messenger\\\\Handler\\\\SanityCheckHandler\\:\\:process\\(\\) is unused\\.$#"
count: 1
path: lib/Messenger/Handler/SanityCheckHandler.php

-
message: "#^Method Pimcore\\\\Messenger\\\\Handler\\\\SearchBackendHandler\\:\\:process\\(\\) is unused\\.$#"
count: 1
path: lib/Messenger/Handler/SearchBackendHandler.php

-
message: "#^Method Pimcore\\\\Messenger\\\\Handler\\\\SearchBackendHandler\\:\\:shouldFlush\\(\\) is unused\\.$#"
count: 1
path: lib/Messenger/Handler/SearchBackendHandler.php

0 comments on commit 64e3a09

Please sign in to comment.