Skip to content

Commit

Permalink
Merge pull request #411 from loic425/feature/improve-code-quality
Browse files Browse the repository at this point in the history
Improve code quality
  • Loading branch information
loic425 committed Apr 23, 2022
2 parents f463b1a + 3b40def commit 5361def
Show file tree
Hide file tree
Showing 69 changed files with 194 additions and 377 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@

final class DashboardController
{
public function __construct(private DashboardStatisticsProviderInterface $statisticsProvider, private Environment $twig)
{
public function __construct(
private DashboardStatisticsProviderInterface $statisticsProvider,
private Environment $twig,
) {
}

public function indexAction(): Response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@

class CustomerStatistic implements StatisticInterface
{
public function __construct(private CustomerRepository $customerRepository, private Environment $twig)
{
public function __construct(
private CustomerRepository $customerRepository,
private Environment $twig,
) {
}

public function generate(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ public function __construct(private FactoryInterface $factory)
{
}

/**
* {@inheritdoc}
*/
public function createMenu(array $options): ItemInterface
{
$menu = $this->factory->createItem('root');
Expand All @@ -27,7 +24,7 @@ public function createMenu(array $options): ItemInterface
return $menu;
}

private function addCustomerSubMenu(ItemInterface $menu): ItemInterface
private function addCustomerSubMenu(ItemInterface $menu): void
{
$customer = $menu
->addChild('customer')
Expand All @@ -37,11 +34,9 @@ private function addCustomerSubMenu(ItemInterface $menu): ItemInterface
$customer->addChild('backend_customer', ['route' => 'sylius_backend_customer_index'])
->setLabel('sylius.ui.customers')
->setLabelAttribute('icon', 'users');

return $customer;
}

private function addConfigurationSubMenu(ItemInterface $menu): ItemInterface
private function addConfigurationSubMenu(ItemInterface $menu): void
{
$configuration = $menu
->addChild('configuration')
Expand All @@ -51,7 +46,5 @@ private function addConfigurationSubMenu(ItemInterface $menu): ItemInterface
$configuration->addChild('backend_admin_user', ['route' => 'sylius_backend_admin_user_index'])
->setLabel('sylius.ui.admin_users')
->setLabelAttribute('icon', 'lock');

return $configuration;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@

class DashboardContext implements Context
{
private $dashboardPage;

public function __construct(DashboardPage $dashboardPage)
public function __construct(private DashboardPage $dashboardPage)
{
$this->dashboardPage = $dashboardPage;
}

/**
Expand All @@ -28,16 +25,16 @@ public function iOpenAdministrationDashboard()
/**
* @Then I should see :number new customers in the list
*/
public function iShouldSeeNewCustomersInTheList($number)
public function iShouldSeeNewCustomersInTheList(int $number)
{
Assert::same($this->dashboardPage->getNumberOfNewCustomersInTheList(), (int) $number);
Assert::same($this->dashboardPage->getNumberOfNewCustomersInTheList(), $number);
}

/**
* @Then I should see :number new customers
*/
public function iShouldSeeNewCustomers($number)
public function iShouldSeeNewCustomers(int $number)
{
Assert::same($this->dashboardPage->getNumberOfNewCustomers(), (int) $number);
Assert::same($this->dashboardPage->getNumberOfNewCustomers(), $number);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,16 @@

class LoginContext implements Context
{
private $dashboardPage;
private $loginPage;

public function __construct(DashboardPage $dashboardPage, LoginPage $loginPage)
{
$this->dashboardPage = $dashboardPage;
$this->loginPage = $loginPage;
public function __construct(
private DashboardPage $dashboardPage,
private LoginPage $loginPage,
) {
}

/**
* @Then I should be able to log in as :username authenticated by :password password
*/
public function iShouldBeAbleToLogInAsAuthenticatedByPassword($username, $password)
public function iShouldBeAbleToLogInAsAuthenticatedByPassword(string $username, string $password): void
{
$this->logInAgain($username, $password);

Expand All @@ -33,7 +30,7 @@ public function iShouldBeAbleToLogInAsAuthenticatedByPassword($username, $passwo
/**
* @Then I should not be able to log in as :username authenticated by :password password
*/
public function iShouldNotBeAbleToLogInAsAuthenticatedByPassword($username, $password)
public function iShouldNotBeAbleToLogInAsAuthenticatedByPassword(string $username, string $password): void
{
$this->logInAgain($username, $password);

Expand All @@ -44,7 +41,7 @@ public function iShouldNotBeAbleToLogInAsAuthenticatedByPassword($username, $pas
/**
* @Then I visit login page
*/
public function iVisitLoginPage()
public function iVisitLoginPage(): void
{
$this->loginPage->open();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,15 @@

final class ManagingAdministratorsContext implements Context
{
private $createPage;
private $indexPage;
private $updatePage;
private $topBarElement;
private $notificationChecker;
private $sharedStorage;
private $objectManager;

public function __construct(
CreatePage $createPage,
IndexPage $indexPage,
UpdatePage $updatePage,
TopBarElement $topBarElement,
NotificationCheckerInterface $notificationChecker,
SharedStorageInterface $sharedStorage,
ObjectManager $objectManager
private CreatePage $createPage,
private IndexPage $indexPage,
private UpdatePage $updatePage,
private TopBarElement $topBarElement,
private NotificationCheckerInterface $notificationChecker,
private SharedStorageInterface $sharedStorage,
private ObjectManager $objectManager,
) {
$this->createPage = $createPage;
$this->indexPage = $indexPage;
$this->updatePage = $updatePage;
$this->topBarElement = $topBarElement;
$this->notificationChecker = $notificationChecker;
$this->sharedStorage = $sharedStorage;
$this->objectManager = $objectManager;
}

/**
Expand Down Expand Up @@ -131,8 +116,7 @@ public function iEnableIt(): void
}

/**
* @When I add it
* @When I try to add it
* @When I (try to) add it
*/
public function iAddIt(): void
{
Expand Down Expand Up @@ -210,7 +194,7 @@ public function thisAdministratorWithNameShouldAppearInTheList(string $username)
*/
public function iShouldSeeAdministratorsInTheList(int $amount = 1): void
{
Assert::same($this->indexPage->countItems(), (int) $amount);
Assert::same($this->indexPage->countItems(), $amount);
}

/**
Expand Down Expand Up @@ -258,7 +242,7 @@ public function thisAdministratorShouldNotBeAdded(): void
/**
* @Then there should not be :email administrator anymore
*/
public function thereShouldBeNoAnymore($email): void
public function thereShouldBeNoAnymore(string $email): void
{
Assert::false($this->indexPage->isSingleResourceOnPage(['email' => $email]));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,16 @@
use App\Tests\Behat\Page\Backend\Customer\ShowPage;
use App\Tests\Behat\Page\Backend\Customer\UpdatePage;
use Behat\Behat\Context\Context;
use Monofony\Bridge\Behat\Service\Resolver\CurrentPageResolverInterface;
use Monofony\Contracts\Core\Model\Customer\CustomerInterface;
use Webmozart\Assert\Assert;

final class ManagingCustomersContext implements Context
{
private IndexPage $indexPage;
private UpdatePage $updatePage;
private ShowPage $showPage;
private CurrentPageResolverInterface $currentPageResolver;

public function __construct(
IndexPage $indexPage,
UpdatePage $updatePage,
ShowPage $showPage,
CurrentPageResolverInterface $currentPageResolver
private IndexPage $indexPage,
private UpdatePage $updatePage,
private ShowPage $showPage,
) {
$this->indexPage = $indexPage;
$this->updatePage = $updatePage;
$this->showPage = $showPage;
$this->currentPageResolver = $currentPageResolver;
}

/**
Expand Down Expand Up @@ -190,7 +179,7 @@ public function iShouldSeeTheCustomerInTheList(string $email): void
/**
* @Then /^I should be notified that ([^"]+) should be ([^"]+)$/
*/
public function iShouldBeNotifiedThatTheElementShouldBe($elementName, $validationMessage): void
public function iShouldBeNotifiedThatTheElementShouldBe(string $elementName, string $validationMessage): void
{
Assert::same(
$this->updatePage->getValidationMessage($elementName),
Expand All @@ -201,7 +190,7 @@ public function iShouldBeNotifiedThatTheElementShouldBe($elementName, $validatio
/**
* @Then the customer with email :email should not appear in the store
*/
public function theCustomerShouldNotAppearInTheStore($email): void
public function theCustomerShouldNotAppearInTheStore(string $email): void
{
$this->indexPage->open();

Expand Down Expand Up @@ -323,22 +312,6 @@ public function thisCustomerShouldBeSubscribedToTheNewsletter(): void
Assert::true($this->updatePage->isSubscribedToTheNewsletter());
}

/**
* @Then I should see the order with number :orderNumber in the list
*/
public function iShouldSeeASingleOrderFromCustomer($orderNumber): void
{
Assert::true($this->indexPage->isSingleResourceOnPage(['number' => $orderNumber]));
}

/**
* @Then I should not see the order with number :orderNumber in the list
*/
public function iShouldNotSeeASingleOrderFromCustomer($orderNumber): void
{
Assert::false($this->indexPage->isSingleResourceOnPage(['number' => $orderNumber]));
}

/**
* @When I do not specify any information
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@

final class NotificationContext implements Context
{
private $notificationChecker;

public function __construct(NotificationCheckerInterface $notificationChecker)
public function __construct(private NotificationCheckerInterface $notificationChecker)
{
$this->notificationChecker = $notificationChecker;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ final class TopBarElement extends Element
{
public function hasAvatarInMainBar(string $avatarPath): bool
{
return false !== strpos($this->getAvatarImagePath(), $avatarPath);
return str_contains($this->getAvatarImagePath(), $avatarPath);
}

public function hasDefaultAvatarInMainBar(): bool
{
return false !== strpos($this->getAvatarImagePath(), '//placehold.it/50x50');
return str_contains($this->getAvatarImagePath(), '//placehold.it/50x50');
}

private function getAvatarImagePath(): string
Expand All @@ -26,6 +26,6 @@ private function getAvatarImagePath(): string
return '';
}

return $image->getAttribute('src');
return (string) $image->getAttribute('src');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

class CreatePage extends AbstractCreatePage implements CreatePageInterface
{
/**
* {@inheritdoc}
*/
public function getRouteName(): string
{
return 'sylius_backend_admin_user_create';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

class IndexPage extends AbstractIndexPage implements IndexPageInterface
{
/**
* {@inheritdoc}
*/
public function getRouteName(): string
{
return 'sylius_backend_admin_user_index';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

class UpdatePage extends AbstractUpdatePage implements UpdatePageInterface
{
/**
* {@inheritdoc}
*/
public function getRouteName(): string
{
return 'sylius_backend_admin_user_update';
Expand All @@ -31,25 +28,16 @@ public function changeUsername(?string $username): void
$this->getElement('username')->setValue($username);
}

/**
* {@inheritdoc}
*/
public function changeEmail(?string $email): void
{
$this->getElement('email')->setValue($email);
}

/**
* {@inheritdoc}
*/
public function changePassword(?string $password): void
{
$this->getElement('password')->setValue($password);
}

/**
* {@inheritdoc}
*/
public function changeLocale(?string $localeCode): void
{
$this->getElement('locale_code')->selectOption($localeCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,11 @@

class IndexPage extends AbstractIndexPage implements IndexPageInterface
{
/**
* {@inheritdoc}
*/
public function getRouteName(): string
{
return 'sylius_backend_customer_index';
}

/**
* {@inheritdoc}
*/
public function getCustomerAccountStatus(CustomerInterface $customer): string
{
$tableAccessor = $this->getTableAccessor();
Expand Down

0 comments on commit 5361def

Please sign in to comment.