Skip to content

Commit

Permalink
[TESTS] PhpStan: fixed all issues in /lib
Browse files Browse the repository at this point in the history
  • Loading branch information
brusch committed Jul 12, 2019
1 parent 0755dbc commit d688a67
Show file tree
Hide file tree
Showing 23 changed files with 45 additions and 93 deletions.
5 changes: 3 additions & 2 deletions lib/Cache/Pool/AbstractCacheItemPool.php
Expand Up @@ -17,6 +17,7 @@
use Pimcore\Cache\Pool\Exception\InvalidArgumentException;
use Psr\Cache\CacheItemInterface;
use Psr\Log\LoggerAwareTrait;
use Symfony\Contracts\Cache\ItemInterface;

abstract class AbstractCacheItemPool implements PimcoreCacheItemPoolInterface
{
Expand Down Expand Up @@ -505,8 +506,8 @@ private function doGet(PimcoreCacheItemPoolInterface $pool, string $key, callabl
$metadata = $item instanceof PimcoreCacheItemInterface ? $item->getMetadata() : [];

if (!$recompute && $metadata) {
$expiry = $metadata[PimcoreCacheItemInterface::METADATA_EXPIRY] ?? false;
$ctime = $metadata[PimcoreCacheItemInterface::METADATA_CTIME] ?? false;
$expiry = $metadata[ItemInterface::METADATA_EXPIRY] ?? false;
$ctime = $metadata[ItemInterface::METADATA_CTIME] ?? false;

if ($recompute = $ctime && $expiry && $expiry <= microtime(true) - $ctime / 1000 * $beta * log(random_int(1, PHP_INT_MAX) / PHP_INT_MAX)) {
// force applying defaultLifetime to expiry
Expand Down
10 changes: 6 additions & 4 deletions lib/Cache/Pool/CacheItem.php
Expand Up @@ -17,8 +17,9 @@
use Cache\TagInterop\TaggableCacheItemInterface;
use Pimcore\Cache\Pool\Exception\InvalidArgumentException;
use Psr\Log\LoggerInterface;
use Symfony\Contracts\Cache\ItemInterface;

class CacheItem implements PimcoreCacheItemInterface
class CacheItem implements PimcoreCacheItemInterface, ItemInterface
{
private const METADATA_EXPIRY_OFFSET = 1527506807;
protected $key;
Expand All @@ -29,6 +30,7 @@ class CacheItem implements PimcoreCacheItemInterface
protected $metadata = [];
protected $previousTags = [];
protected $tags = [];
protected $newMetadata = [];

/**
* @param string $key
Expand Down Expand Up @@ -100,10 +102,10 @@ public function getDefaultLifetime()
/**
* {@inheritdoc}
*/
public function tag($tags): PimcoreCacheItemInterface
public function tag($tags): ItemInterface
{
if (!$this->isTaggable) {
throw new LogicException(sprintf('Cache item "%s" comes from a non tag-aware pool: you cannot tag it.', $this->key));
if (!isset($this->isTaggable) || !$this->isTaggable) {
throw new \LogicException(sprintf('Cache item "%s" comes from a non tag-aware pool: you cannot tag it.', $this->key));
}
if (!\is_iterable($tags)) {
$tags = [$tags];
Expand Down
32 changes: 0 additions & 32 deletions lib/Console/AbstractConsoleCommandPlugin.php

This file was deleted.

3 changes: 1 addition & 2 deletions lib/Document/Tag/DelegatingTagHandler.php
Expand Up @@ -18,7 +18,6 @@
use Pimcore\Model\Document\Tag;
use Pimcore\Model\Document\Tag\Area\Info;
use Pimcore\Templating\Model\ViewModelInterface;
use Pimcore\View;

class DelegatingTagHandler implements TagHandlerInterface
{
Expand All @@ -42,7 +41,7 @@ public function addHandler(TagHandlerInterface $handler)
/**
* Get the matching handler for a view
*
* @param ViewModelInterface|View $view
* @param ViewModelInterface $view
*
* @return TagHandlerInterface
*/
Expand Down
Expand Up @@ -157,11 +157,11 @@ private function initializeUser(InputInterface $input)
$user = User::getByName($username);

if (!$user) {
throw new \InvalidArgumentException(sprintf('User "%s" could not be loaded'));
throw new \InvalidArgumentException(sprintf('User "%s" could not be loaded', $username));
}

if (!$user->isAdmin()) {
throw new \InvalidArgumentException(sprintf('User "%s" does not have admin rights'));
throw new \InvalidArgumentException(sprintf('User "%s" does not have admin rights', $username));
}

// See ElementListener. The UserLoader will be used to fetch the admin user when rendering
Expand Down
5 changes: 2 additions & 3 deletions lib/Document/Tag/TagHandlerInterface.php
Expand Up @@ -17,14 +17,13 @@
use Pimcore\Model\Document\Tag;
use Pimcore\Model\Document\Tag\Area\Info;
use Pimcore\Templating\Model\ViewModelInterface;
use Pimcore\View;

interface TagHandlerInterface
{
/**
* Determine if handler supports the tag
*
* @param ViewModelInterface|View $view
* @param ViewModelInterface $view
*
* @return bool
*/
Expand Down Expand Up @@ -60,7 +59,7 @@ public function renderAreaFrontend(Info $info);
/**
* Render a sub-action (snippet, renderlet)
*
* @param ViewModelInterface|View $view
* @param ViewModelInterface $view
* @param string $controller
* @param string $action
* @param string|null $parent Bundle
Expand Down
12 changes: 1 addition & 11 deletions lib/Event/Model/Asset/ResolveUploadTargetEvent.php
Expand Up @@ -14,12 +14,10 @@

namespace Pimcore\Event\Model\Asset;

use Pimcore\Event\Model\ElementEventInterface;
use Pimcore\Event\Traits\ArgumentsAwareTrait;
use Pimcore\Model\Asset;
use Symfony\Component\EventDispatcher\Event;

class ResolveUploadTargetEvent extends Event implements ElementEventInterface
class ResolveUploadTargetEvent extends Event
{
use ArgumentsAwareTrait;

Expand Down Expand Up @@ -99,12 +97,4 @@ public function setParentId($parentId): void
{
$this->parentId = $parentId;
}

/**
* @return Asset
*/
public function getElement()
{
return $this->getAsset();
}
}
2 changes: 1 addition & 1 deletion lib/Event/Targeting/TargetingEvent.php
Expand Up @@ -26,7 +26,7 @@ class TargetingEvent extends Event
/**
* @var VisitorInfo
*/
private $visitorInfo;
protected $visitorInfo;

public function __construct(VisitorInfo $visitorInfo)
{
Expand Down
2 changes: 2 additions & 0 deletions lib/Google/Cse.php
Expand Up @@ -161,6 +161,8 @@ public function __construct($googleResponse = null)
*/
public function readGoogleResponse(\Google_Service_Customsearch_Search $googleResponse)
{
$items = [];

$this->setRaw($googleResponse);

// set search results
Expand Down
2 changes: 1 addition & 1 deletion lib/Kernel.php
Expand Up @@ -94,7 +94,7 @@ public function getLogDir()
*/
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(function (ContainerBuilder $container) use ($loader) {
$loader->load(function (ContainerBuilder $container) {
$this->registerExtensionConfigFileResources($container);
});

Expand Down
5 changes: 3 additions & 2 deletions lib/Mail.php
Expand Up @@ -624,10 +624,11 @@ public function sendWithoutRendering(\Swift_Mailer $mailer = null)
if ($event->hasArgument('mailer')) {
$mailer = $event->getArgument('mailer');
try {
$mailer->send($this, $emailaddress);
$failedRecipients = [];
$mailer->send($this, $failedRecipients);
} catch (\Exception $e) {
$mailer->getTransport()->stop();
throw new \Exception($emailaddress[0].' - '.$e->getMessage());
throw new \Exception($failedRecipients[0].' - '.$e->getMessage());
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/Migrations/SqlFileWriter.php
Expand Up @@ -50,6 +50,7 @@ public function __construct(Configuration $configuration, $destPath, OutputWrite
$this->throwInvalidArgumentException('Destination file must be specified.');
}

$this->configuration = $configuration;
$this->destPath = $destPath;
$this->outputWriter = $outputWriter;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Placeholder.php
Expand Up @@ -160,7 +160,7 @@ public function detectPlaceholders($contentString, $params, $document = null)
} elseif (!is_array($configArray)) {
throw new \Exception('The JSON string in the PlaceholderConfig should be an array.');
}
$placeholderConfig = new \Pimcore\Config\Config($configArray, null, ['ignoreconstants' => true]);
$placeholderConfig = new \Pimcore\Config\Config($configArray, null);
} catch (\Exception $e) {
Logger::warn('PlaceholderConfig is not a valid JSON string. PlaceholderConfig for ' . $placeholderClass . ' ignored.');
continue;
Expand Down
2 changes: 1 addition & 1 deletion lib/Routing/Redirect/Csv.php
Expand Up @@ -173,7 +173,7 @@ private function processImportData(array $data, array &$stats)
$redirect = null;

if ($data['id']) {
$redirect = Redirect::getById($data['id'], true);
$redirect = Redirect::getById($data['id']);
$stats['updated']++;
} else {
$redirect = new Redirect();
Expand Down
7 changes: 4 additions & 3 deletions lib/Templating/Helper/HeadMeta.php
Expand Up @@ -201,7 +201,8 @@ public function __call($method, $args)
$item = $this->createData($type, $args[0], $args[1], $args[2]);

if ('offsetSet' == $action) {
return $this->offsetSet($index, $item);
$this->offsetSet($index, $item);
return $this;
}

$this->$action($item);
Expand Down Expand Up @@ -258,7 +259,7 @@ public function offsetSet($index, $value)
throw new Exception('Invalid value passed to offsetSet; please use offsetSetName() or offsetSetHttpEquiv()');
}

return $this->getContainer()->offsetSet($index, $value);
$this->getContainer()->offsetSet($index, $value);
}

/**
Expand Down Expand Up @@ -319,7 +320,7 @@ public function set($value)
}
}

return $this->append($value);
$this->append($value);
}

/**
Expand Down
17 changes: 0 additions & 17 deletions lib/Templating/Helper/Placeholder.php
Expand Up @@ -56,11 +56,6 @@ class Placeholder extends AbstractHelper
*/
protected $_regKey = 'Placeholder';

/**
* @var ContainerService
*/
protected $containerService;

/**
* @var Container[]
*/
Expand All @@ -71,18 +66,6 @@ public function getName()
return 'placeholder';
}

/**
* AbstractHelper constructor.
*
* @param ContainerService $containerService
*
* @internal param Container $container
*/
public function __construct(ContainerService $containerService)
{
$this->containerService = $containerService;
}

/**
* Retrieve object instance; optionally add meta tag
*
Expand Down
2 changes: 1 addition & 1 deletion lib/Tool/ClassUtils.php
Expand Up @@ -51,7 +51,7 @@ public static function findClassName(\SplFileInfo $file): string
$gettingClass = false;

if (!$file->isReadable() || !file_exists($file->getPathname())) {
throw new \InvalidArgumentException(sprintf('File %s does not exist or is not readable'));
throw new \InvalidArgumentException(sprintf('File %s does not exist or is not readable', $file->getPathname()));
}

$content = '';
Expand Down
4 changes: 0 additions & 4 deletions lib/Tool/RestClient/AbstractRestClient.php
Expand Up @@ -782,10 +782,6 @@ public function getAssetById($id, $decode = true, $idMapper = null, $light = fal
$uri = $protocol . $this->getHost() . $tmpPath . '/thumb_' . $asset->getId() . '__' . $thumbnail;
$client->setUri($uri);

if ($this->getLoggingEnabled()) {
print ' =>' . $uri . "\n";
}

$result = $client->request();
if ($result->getStatus() == 200) {
$data = $result->getBody();
Expand Down
Expand Up @@ -28,7 +28,7 @@ class Xliff12DataExtractor implements ImportDataExtractorInterface
protected $xliffEscaper;

/**
* @var TranslationItemResolver\
* @var TranslationItemResolverInterface
*/
protected $translationItemResolver;

Expand Down
5 changes: 3 additions & 2 deletions lib/Workflow/Manager.php
Expand Up @@ -21,7 +21,7 @@
use Pimcore\Workflow\EventSubscriber\NotesSubscriber;
use Pimcore\Workflow\Place\PlaceConfig;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Workflow\Exception\InvalidARgumentException;
use Symfony\Component\Workflow\Exception\InvalidArgumentException;
use Symfony\Component\Workflow\Exception\LogicException;
use Symfony\Component\Workflow\Marking;
use Symfony\Component\Workflow\Registry;
Expand Down Expand Up @@ -201,7 +201,8 @@ public function getWorkflowIfExists($subject, string $workflowName): ?Workflow
{
try {
$workflow = $this->workflowRegistry->get($subject, $workflowName);
} catch (InvalidARgumentException $e) { // workflow does not apply to given subject
} catch (InvalidArgumentException $e) {
// workflow does not apply to given subject
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Workflow/Place/OptionsProvider.php
Expand Up @@ -41,7 +41,7 @@ public function __construct(Manager $workflowManager, TranslatorInterface $trans

/**
* @param array $context
* @param Data $fieldDefinition
* @param \Pimcore\Model\DataObject\ClassDefinition\Data $fieldDefinition
*
* @return array
*
Expand Down
4 changes: 2 additions & 2 deletions lib/Workflow/Transition.php
Expand Up @@ -30,8 +30,8 @@ class Transition extends \Symfony\Component\Workflow\Transition implements Notes
* Transition constructor.
*
* @param string $name
* @param string|\string[] $froms
* @param string|\string[] $tos
* @param string|string[] $froms
* @param string|string[] $tos
* @param array $options
*/
public function __construct($name, $froms, $tos, $options = [])
Expand Down
8 changes: 8 additions & 0 deletions phpstan.neon
Expand Up @@ -11,8 +11,13 @@ parameters:
- '**/Generator/DoctrineCrudGenerator.php'
- '**/EcommerceFrameworkBundle/Resources/views/Voucher/parts/paginator.html.php'
- '**/EcommerceFrameworkBundle/Resources/views/Includes/paging.html.php'
- '**/Processor/PdfReactor8.php'
- '**/simple_html_dom.php'
- '**/PDFreactor.class.php'

ignoreErrors:
- '/(snappy|lz4)_(un)?compress/'
- '/Instantiated class COM not found/'
- '/Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition::children()/'
- '/(OnlineShopVoucherToken|OnlineShopVoucherSeries|VoucherTokenTypeSingle|VoucherTokenTypePattern|OnlineShopOrder|OnlineShopOrderItem|OnlineShopTaxClass|TaxEntry|DataObject\\Customer)/'
-
Expand All @@ -30,3 +35,6 @@ parameters:
-
message: '#Undefined variable: \$(this|view|app)#'
path: '**/*.js.php'
-
message: '/Zend_Log/'
path: '**/Log/ApplicationLogger.php'

0 comments on commit d688a67

Please sign in to comment.