Skip to content

Commit

Permalink
Merge pull request #1220 from dpfaffenbauer/stan-level-3
Browse files Browse the repository at this point in the history
[PHPStan] level-3
  • Loading branch information
dpfaffenbauer authored Jan 10, 2020
2 parents bb79293 + cd4c7dd commit 3056d80
Show file tree
Hide file tree
Showing 82 changed files with 283 additions and 158 deletions.
2 changes: 1 addition & 1 deletion etc/_scripts/phpstan
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ set -e
echo "RUNNING PHPSTAN"

bin/console cache:warmup --env=dev
vendor/bin/phpstan analyse -c phpstan.travis.neon src -l 2
vendor/bin/phpstan analyse -c phpstan.travis.neon src -l 3
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ parameters:
- '/Constant PIMCORE_WEB_ROOT not found./'
- '/Constant PIMCORE_DEVMODE not found./'
- '/Class Zend_Paginator_Adapter_Interface not found and could not be autoloaded./'
- '/Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface::dispatch\(\)/'

- '/Class LuceneSearchBundle/'
- '/unknown class LuceneSearchBundle/'
Expand Down
15 changes: 12 additions & 3 deletions src/CoreShop/Behat/Context/Cli/InstallerContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace CoreShop\Behat\Context\Cli;

use Behat\Behat\Context\Context;
use CoreShop\Bundle\CoreBundle\Command\AbstractInstallCommand;
use CoreShop\Bundle\CoreBundle\Command\InstallCommand;
use CoreShop\Bundle\CoreBundle\Command\InstallDemoCommand;
use CoreShop\Bundle\CoreBundle\Command\InstallFixturesCommand;
Expand All @@ -39,7 +40,7 @@ final class InstallerContext implements Context
private $tester;

/**
* @var InstallCommand
* @var AbstractInstallCommand
*/
private $command;

Expand All @@ -63,7 +64,11 @@ public function iRunCoreShopInstallFixturesCommand()

$this->application = new Application($this->kernel);
$this->application->add($installCommand);
$this->command = $this->application->find('coreshop:install:fixtures');
$command = $this->application->find('coreshop:install:fixtures');

Assert::isInstanceOf($command, InstallFixturesCommand::class);

$this->command = $command;
$this->tester = new CommandTester($this->command);
}

Expand All @@ -79,7 +84,11 @@ public function iRunCoreShopInstallSampleDataCommand()

$this->application = new Application($this->kernel);
$this->application->add($installCommand);
$this->command = $this->application->find('coreshop:install:demo');
$command = $this->application->find('coreshop:install:demo');

Assert::isInstanceOf($command, InstallDemoCommand::class);

$this->command = $command;
$this->tester = new CommandTester($this->command);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class StorePrice extends Model\DataObject\ClassDefinition\Data implements Model\
public $fieldtype = 'coreShopStorePrice';

/**
* @var float
* @var int
*/
public $width;

Expand Down
6 changes: 5 additions & 1 deletion src/CoreShop/Bundle/CoreBundle/CoreExtension/StoreValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class StoreValues extends Model\DataObject\ClassDefinition\Data implements
public $fieldtype = 'coreShopStoreValues';

/**
* @var float
* @var int
*/
public $width;

Expand Down Expand Up @@ -725,6 +725,10 @@ protected function clearRemovedUnitDefinitions(
if ($isUnitDefinitionsSerialized) {
$found = false;

if (!isset($unitDefinitions['unitDefinitions']) || !is_iterable($unitDefinitions['unitDefinitions'])) {
continue;
}

foreach ($unitDefinitions['unitDefinitions'] as $unitDefinition) {
if ($unitDefinition['id'] === $unitDefinitionPrice->getUnitDefinition()->getId()) {
$found = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
final class CustomerLoginService implements CustomerLoginServiceInterface
{
/**
* @var TokenStorage
* @var TokenStorageInterface
*/
private $securityTokenStorage;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ final class ProductAvailabilityEventListener
private $pimcoreModelFactory;

/**
* @var PurchasableInterface[]
* @var int[]
*/
private $productIdsToCheck = [];

Expand All @@ -62,7 +62,7 @@ public function preUpdateListener(DataObjectEvent $event)
return;
}

if (in_array($object->getId(), $this->productIdsToCheck)) {
if (in_array($object->getId(), $this->productIdsToCheck, true)) {
return;
}

Expand Down Expand Up @@ -99,7 +99,7 @@ public function postUpdateListener(DataObjectEvent $event)
return;
}

if (!in_array($object->getId(), $this->productIdsToCheck)) {
if (!in_array($object->getId(), $this->productIdsToCheck, true)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,20 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$lastEnd = -1;

/**
* @var int $rowIndex
* @var QuantityRangeInterface $quantityRange
* @var int $rowIndex
* @var array $quantityRangeToCheck
*/
foreach ($quantityRangesToCheck as $quantityRange) {
$realRowIndex = $quantityRange['row'];
$startingFrom = $quantityRange['startingFrom'];
foreach ($quantityRangesToCheck as $quantityRangeToCheck) {
$realRowIndex = $quantityRangeToCheck['row'];
$startingFrom = $quantityRangeToCheck['startingFrom'];

if ((float) $startingFrom < 0) {
$form->addError(new FormError('Field "starting from" in row ' . $realRowIndex . ' needs to be greater or equal than 0'));

break;
} elseif ((float) $startingFrom <= $lastEnd) {
}

if((float) $startingFrom <= $lastEnd) {
$form->addError(new FormError('Field "starting from" in row ' . $realRowIndex . ' needs to be greater than ' . $lastEnd));

break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public function refreshUser(UserInterface $user)
throw new UnsupportedUserException();
}

/**
* @var CustomerInterface $refreshedUser
*/
$refreshedUser = $this->customerRepository->find($user->getId());

return $refreshedUser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface ConfigurationHelperInterface extends HelperInterface
* @param string $name
* @param StoreInterface $store
*
* @return array
* @return mixed
*/
public function getConfiguration($name, StoreInterface $store = null);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MoneyCurrency extends Model\DataObject\ClassDefinition\Data implements Mod
public $fieldtype = 'coreShopMoneyCurrency';

/**
* @var float
* @var int
*/
public $width;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface ConvertCurrencyHelperInterface
* @param string|null $sourceCurrencyCode
* @param string|null $targetCurrencyCode
*
* @return string
* @return int
*
* @throws \InvalidArgumentException
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace CoreShop\Bundle\CustomerBundle\Pimcore\Repository;

use CoreShop\Bundle\ResourceBundle\Pimcore\PimcoreRepository;
use CoreShop\Component\Customer\Model\CustomerInterface;
use CoreShop\Component\Customer\Repository\CustomerRepositoryInterface;

class CustomerRepository extends PimcoreRepository implements CustomerRepositoryInterface
Expand All @@ -26,7 +27,7 @@ public function findByResetToken($resetToken)
$list->setCondition('passwordResetHash = ?', [$resetToken]);
$objects = $list->load();

if (count($objects) === 1) {
if (count($objects) === 1 && $objects[0] instanceof CustomerInterface) {
return $objects[0];
}

Expand All @@ -42,7 +43,7 @@ public function findByNewsletterToken($newsletterToken)
$list->setCondition('newsletterToken = ?', [$newsletterToken]);
$objects = $list->load();

if (count($objects) === 1) {
if (count($objects) === 1 && $objects[0] instanceof CustomerInterface) {
return $objects[0];
}

Expand Down Expand Up @@ -71,11 +72,11 @@ public function findUniqueByEmail($email, $isGuest)

$users = $list->getObjects();

if (count($users) > 0) {
if (count($users) > 0 && $users[0] instanceof CustomerInterface) {
return $users[0];
}

return false;
return null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ protected function getCartManager()
}

/**
* @return \CoreShop\Component\Order\Transformer\CartToOrderTransformer
* @return \CoreShop\Component\Order\Transformer\ProposalTransformerInterface
*/
protected function getCartToOrderTransformer()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,12 @@ public function confirmNewsletterAction(Request $request)
protected function getCustomer()
{
try {
return $this->get('coreshop.context.customer')->getCustomer();
/**
* @var CustomerInterface $customer
*/
$customer = $this->get('coreshop.context.customer')->getCustomer();

return $customer;
} catch (\Exception $ex) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,13 @@ protected function getClassificationStoreGroupConfiguration(DataObject\Classific
$result['nodeType'] = 'classificationstore';
$result['childs'] = [];

foreach ($config->getRelations() as $relation) {
$relations = $config->getRelations();

if (!is_array($relations)) {
return $result;
}

foreach ($relations as $relation) {
if ($relation instanceof DataObject\Classificationstore\KeyGroupRelation) {
$keyId = $relation->getKeyId();

Expand Down
7 changes: 6 additions & 1 deletion src/CoreShop/Bundle/IndexBundle/CoreShopIndexBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ public function getComposerPackageName()
public function getInstaller()
{
if ($this->container->has(Installer::class)) {
return $this->container->get(Installer::class);
/**
* @var Installer $installer
*/
$installer = $this->container->get(Installer::class);

return $installer;
}

return null;
Expand Down
2 changes: 1 addition & 1 deletion src/CoreShop/Bundle/IndexBundle/Factory/ListingFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function createList(IndexInterface $index)
}

/**
* @var WorkerInterface
* @var WorkerInterface $worker
*/
$worker = $this->workerServiceRegistry->get($worker);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Listing extends AbstractListing implements OrderAwareListingInterface, Ext
protected $dao;

/**
* @var string
* @var OrderInterface|string|null
*/
protected $order;

Expand Down Expand Up @@ -361,6 +361,7 @@ public function load(array $options = [])
$this->objects = [];
foreach ($objectRaws as $raw) {
$object = $this->loadElementById($raw['o_id']);

if ($object instanceof Concrete) {
if ($object->getClassName() === $className) {
$this->objects[] = $object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class Dao
{
/**
* @var \Pimcore\Db\Connection
* @var \Pimcore\Db\ConnectionInterface
*/
private $database;

Expand Down
2 changes: 1 addition & 1 deletion src/CoreShop/Bundle/MoneyBundle/CoreExtension/Money.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Money extends Model\DataObject\ClassDefinition\Data implements
public $fieldtype = 'coreShopMoney';

/**
* @var float
* @var int
*/
public $width;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ protected function getItemDetails(SaleInterface $sale)
/**
* @param SaleItemInterface $item
*
* @return array<string,integer|null|string>
* @return array
*/
protected function prepareSaleItem(SaleItemInterface $item)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ protected function getItemDetails(CartInterface $cart)
/**
* @param CartItemInterface $item
*
* @return array<string,integer|null|string>
* @return array
*/
protected function prepareCartItem(CartItemInterface $item)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Carbon\Carbon;
use CoreShop\Bundle\ResourceBundle\Controller\PimcoreController;
use CoreShop\Bundle\WorkflowBundle\Manager\StateMachineManager;
use CoreShop\Component\Core\Repository\PaymentProviderRepositoryInterface;
use CoreShop\Component\Order\Model\OrderInterface;
use CoreShop\Component\Order\Model\OrderPaymentInterface;
use CoreShop\Component\Payment\Model\PaymentInterface;
Expand Down Expand Up @@ -147,7 +148,7 @@ private function getEntityManager()
}

/**
* @return PaymentRepositoryInterface
* @return PaymentProviderRepositoryInterface
*/
private function getPaymentProviderRepository()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use CoreShop\Component\Order\Renderer\OrderDocumentRendererInterface;
use CoreShop\Component\Order\Repository\OrderShipmentRepositoryInterface;
use CoreShop\Component\Order\ShipmentStates;
use CoreShop\Component\Order\Transformer\OrderDocumentTransformerInterface;
use CoreShop\Component\Order\Transformer\OrderToShipmentTransformer;
use CoreShop\Component\Resource\Factory\FactoryInterface;
use CoreShop\Component\Resource\Repository\PimcoreRepositoryInterface;
Expand Down Expand Up @@ -243,7 +244,7 @@ protected function getShipmentFactory()
}

/**
* @return OrderToShipmentTransformer
* @return OrderDocumentTransformerInterface
*/
protected function getOrderToShipmentTransformer()
{
Expand Down
Loading

0 comments on commit 3056d80

Please sign in to comment.