Skip to content

Commit

Permalink
Merge pull request #191 from loic425/features/psalm-level-5
Browse files Browse the repository at this point in the history
psalm level 5
  • Loading branch information
loic425 committed Jun 5, 2019
2 parents 72a34a6 + 025e57a commit 1648ffb
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 68 deletions.
7 changes: 5 additions & 2 deletions Makefile.dist
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ stop:

test: validate-all test-all

test-all: test-phpspec test-phpstan test-phpunit test-infection test-all-behat
test-all: test-phpspec test-phpstan test-phpstan test-phpunit test-infection test-all-behat

test-behat:
APP_ENV=test vendor/bin/behat --tags=${TAGS} ${ARGS}
Expand All @@ -45,11 +45,14 @@ test-infection:
test-phpspec:
phpdbg -qrr vendor/bin/phpspec run -n ${ARGS}

test-phpstan::
test-phpstan:
APP_ENV=dev bin/console cache:clear
APP_ENV=dev bin/console cache:warmup
vendor/bin/phpstan analyse -c phpstan.neon -l 1 src

test-psalm:
vendor/bin/psalm --show-info=false

test-phpunit:
APP_ENV=test vendor/bin/phpunit ${ARGS}

Expand Down
15 changes: 0 additions & 15 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,5 @@
<MissingDocblockType errorLevel="info" />
<ImplementedReturnTypeMismatch errorLevel="info" />

<!-- level 6 issues - really bad things -->

<InvalidNullableReturnType errorLevel="info" />
<NullableReturnStatement errorLevel="info" />
<InvalidFalsableReturnType errorLevel="info" />
<FalsableReturnStatement errorLevel="info" />

<MoreSpecificImplementedParamType errorLevel="info" />
<LessSpecificImplementedReturnType errorLevel="info" />

<InvalidReturnStatement errorLevel="info" />
<InvalidReturnType errorLevel="info" />
<UndefinedThisPropertyAssignment errorLevel="info" />
<UndefinedInterfaceMethod errorLevel="info" />

</issueHandlers>
</psalm>
24 changes: 12 additions & 12 deletions spec/App/EventListener/DefaultUsernameORMListenerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace spec\App\EventListener;

use App\Entity\Customer;
use App\Entity\CustomerInterface;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Event\OnFlushEventArgs;
use Doctrine\ORM\Mapping\ClassMetadata;
Expand All @@ -19,7 +19,7 @@ function it_sets_usernames_on_customer_create(
OnFlushEventArgs $onFlushEventArgs,
EntityManager $entityManager,
UnitOfWork $unitOfWork,
Customer $customer,
CustomerInterface $customer,
UserInterface $user,
ClassMetadata $userMetadata
): void {
Expand Down Expand Up @@ -48,7 +48,7 @@ function it_updates_usernames_on_customer_email_change(
OnFlushEventArgs $onFlushEventArgs,
EntityManager $entityManager,
UnitOfWork $unitOfWork,
Customer $customer,
CustomerInterface $customer,
UserInterface $user,
ClassMetadata $userMetadata
): void {
Expand Down Expand Up @@ -77,7 +77,7 @@ function it_updates_usernames_on_customer_email_canonical_change(
OnFlushEventArgs $onFlushEventArgs,
EntityManager $entityManager,
UnitOfWork $unitOfWork,
Customer $customer,
CustomerInterface $customer,
UserInterface $user,
ClassMetadata $userMetadata
): void {
Expand Down Expand Up @@ -106,7 +106,7 @@ function it_does_not_update_usernames_when_customer_emails_are_the_same(
OnFlushEventArgs $onFlushEventArgs,
EntityManager $entityManager,
UnitOfWork $unitOfWork,
Customer $customer,
CustomerInterface $customer,
UserInterface $user,
ClassMetadata $userMetadata
): void {
Expand Down Expand Up @@ -134,7 +134,7 @@ function it_does_nothing_on_customer_create_when_no_user_associated(
OnFlushEventArgs $onFlushEventArgs,
EntityManager $entityManager,
UnitOfWork $unitOfWork,
Customer $customer
CustomerInterface $customer
): void {
$onFlushEventArgs->getEntityManager()->willReturn($entityManager);
$entityManager->getUnitOfWork()->willReturn($unitOfWork);
Expand All @@ -153,7 +153,7 @@ function it_does_nothing_on_customer_update_when_no_user_associated(
OnFlushEventArgs $onFlushEventArgs,
EntityManager $entityManager,
UnitOfWork $unitOfWork,
Customer $customer
CustomerInterface $customer
): void {
$onFlushEventArgs->getEntityManager()->willReturn($entityManager);
$entityManager->getUnitOfWork()->willReturn($unitOfWork);
Expand Down Expand Up @@ -208,7 +208,7 @@ function it_skips_objects_other_than_customers(
EntityManager $entityManager,
UnitOfWork $unitOfWork,
\stdClass $stdObject,
Customer $customer,
CustomerInterface $customer,
UserInterface $user,
ClassMetadata $userMetadata
): void {
Expand Down Expand Up @@ -238,8 +238,8 @@ function it_skips_customers_without_users_associated(
OnFlushEventArgs $onFlushEventArgs,
EntityManager $entityManager,
UnitOfWork $unitOfWork,
Customer $customerWithoutUser,
Customer $customerWithUser,
CustomerInterface $customerWithoutUser,
CustomerInterface $customerWithUser,
UserInterface $user,
ClassMetadata $userMetadata
): void {
Expand Down Expand Up @@ -271,8 +271,8 @@ function it_skips_customers_with_same_emails(
OnFlushEventArgs $onFlushEventArgs,
EntityManager $entityManager,
UnitOfWork $unitOfWork,
Customer $customerWithSameEmail,
Customer $customerWithDifferentEmail,
CustomerInterface $customerWithSameEmail,
CustomerInterface $customerWithDifferentEmail,
UserInterface $userWithSameEmail,
UserInterface $userWithDifferentEmail,
ClassMetadata $userMetadata
Expand Down
6 changes: 3 additions & 3 deletions spec/App/EventListener/PasswordUpdaterListenerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace spec\App\EventListener;

use App\Entity\Customer;
use App\Entity\CustomerInterface;
use PhpSpec\ObjectBehavior;
use Sylius\Component\User\Model\UserInterface;
use Sylius\Component\User\Security\PasswordUpdaterInterface;
Expand All @@ -21,7 +21,7 @@ function it_updates_password_for_customer(
PasswordUpdaterInterface $passwordUpdater,
GenericEvent $event,
UserInterface $user,
Customer $customer
CustomerInterface $customer
): void {
$event->getSubject()->willReturn($customer);
$customer->getUser()->willReturn($user);
Expand All @@ -44,7 +44,7 @@ function it_does_not_update_password_if_subject_is_not_instance_of_customer_inte
function it_does_not_update_password_if_customer_does_not_have_user(
PasswordUpdaterInterface $passwordUpdater,
GenericEvent $event,
Customer $customer
CustomerInterface $customer
): void {
$event->getSubject()->willReturn($customer);
$customer->getUser()->willReturn(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace spec\App\Form\EventSubscriber;

use App\Entity\Customer;
use App\Entity\CustomerInterface;
use PhpSpec\ObjectBehavior;
use App\Entity\AppUser;
use Sylius\Component\Resource\Repository\RepositoryInterface;
Expand Down Expand Up @@ -33,9 +33,9 @@ function it_listens_on_pre_submit_data_event(): void
function it_sets_user_for_existing_customer(
FormEvent $event,
FormInterface $form,
Customer $customer,
CustomerInterface $customer,
RepositoryInterface $customerRepository,
Customer $existingCustomer,
CustomerInterface $existingCustomer,
AppUser $user
): void {
$event->getForm()->willReturn($form);
Expand Down Expand Up @@ -68,9 +68,9 @@ function it_throws_unexpected_type_exception_if_data_is_not_customer_type(
function it_does_not_set_user_if_customer_with_given_email_has_set_user(
FormEvent $event,
FormInterface $form,
Customer $customer,
CustomerInterface $customer,
RepositoryInterface $customerRepository,
Customer $existingCustomer,
CustomerInterface $existingCustomer,
AppUser $user
): void {
$event->getForm()->willReturn($form);
Expand All @@ -90,9 +90,9 @@ function it_does_not_set_user_if_customer_with_given_email_has_set_user(
function it_does_not_set_user_if_email_is_empty(
FormEvent $event,
FormInterface $form,
Customer $customer,
CustomerInterface $customer,
RepositoryInterface $customerRepository,
Customer $existingCustomer,
CustomerInterface $existingCustomer,
AppUser $user
): void {
$event->getForm()->willReturn($form);
Expand Down
31 changes: 8 additions & 23 deletions src/Command/Installer/SetupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Doctrine\Common\Persistence\ObjectManager;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Sylius\Component\User\Repository\UserRepositoryInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -28,36 +29,22 @@

final class SetupCommand extends Command
{
/**
* @var ObjectManager
*/
/** @var ObjectManager */
private $adminUserManager;

/**
* @var FactoryInterface
*/
/** @var FactoryInterface */
private $adminUserFactory;

/**
* @var RepositoryInterface
*/
/** @var UserRepositoryInterface */
private $adminUserRepository;

/**
* @var ValidatorInterface
*/
/** @var ValidatorInterface */
private $validator;

/**
* @param ObjectManager $adminUserManager
* @param FactoryInterface $adminUserFactory
* @param RepositoryInterface $adminUserRepository
* @param ValidatorInterface $validator
*/
public function __construct(
ObjectManager $adminUserManager,
FactoryInterface $adminUserFactory,
RepositoryInterface $adminUserRepository,
UserRepositoryInterface $adminUserRepository,
ValidatorInterface $validator
) {
$this->adminUserManager = $adminUserManager;
Expand Down Expand Up @@ -94,17 +81,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int
*/
protected function setupAdministratorUser(InputInterface $input, OutputInterface $output)
protected function setupAdministratorUser(InputInterface $input, OutputInterface $output): void
{
$output->writeln('Create your administrator account.');

try {
$user = $this->configureNewUser($this->adminUserFactory->createNew(), $input, $output);
} catch (\InvalidArgumentException $exception) {
return 0;
return;
}

$user->setEnabled(true);
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): void
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('app');
Expand Down
2 changes: 1 addition & 1 deletion src/EventListener/DefaultUsernameORMListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Doctrine\ORM\Event\OnFlushEventArgs;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\UnitOfWork;
use Sylius\Component\Customer\Model\CustomerInterface;
use App\Entity\CustomerInterface;
use Sylius\Component\User\Model\UserInterface;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/EventListener/PasswordUpdaterListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

namespace App\EventListener;

use App\Entity\CustomerInterface;
use Sylius\Bundle\UserBundle\EventListener\PasswordUpdaterListener as BasePasswordUpdaterListener;
use Sylius\Component\Customer\Model\CustomerInterface;
use Sylius\Component\Resource\Exception\UnexpectedTypeException;
use Symfony\Component\EventDispatcher\GenericEvent;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace App\Form\EventSubscriber;

use Sylius\Component\Customer\Model\CustomerInterface;
use App\Entity\CustomerInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
Expand Down
11 changes: 9 additions & 2 deletions src/Installer/Provider/DatabaseSetupCommandsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Doctrine\Bundle\DoctrineBundle\Registry;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -143,14 +144,20 @@ private function isSchemaPresent()
*/
private function getDatabaseName()
{
return $this->doctrineRegistry->getManager()->getConnection()->getDatabase();
/** @var EntityManagerInterface $manager */
$manager = $this->doctrineRegistry->getManager();

return $manager->getConnection()->getDatabase();
}

/**
* @return AbstractSchemaManager
*/
private function getSchemaManager()
{
return $this->doctrineRegistry->getManager()->getConnection()->getSchemaManager();
/** @var EntityManagerInterface $manager */
$manager = $this->doctrineRegistry->getManager();

return $manager->getConnection()->getSchemaManager();
}
}

0 comments on commit 1648ffb

Please sign in to comment.