Skip to content

Commit

Permalink
Issue: #155: Remove repetitive property declarations.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmerlin committed Feb 14, 2023
1 parent ca4aa2f commit 23099e0
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 90 deletions.
11 changes: 5 additions & 6 deletions src/Admin/src/Authentication/AuthenticationAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,22 @@

class AuthenticationAdapter implements AdapterInterface
{
private EntityManager $entityManager;
private const METHOD_NOT_EXISTS = "Method %s not found in %s .";
private const OPTION_VALUE_NOT_PROVIDED = "Option '%s' not provided for '%s' option.";

private string $identity;

private string $credential;

private EntityManager $entityManager;

private array $config = [];

/**
* AuthenticationAdapter constructor.
* @param EntityManager $entityManager
* @param array $config
*
* @Inject({EntityManager::class, "config.doctrine.authentication"})
* @Inject({
* EntityManager::class,
* "config.doctrine.authentication"
* })
*/
public function __construct(EntityManager $entityManager, array $config)
{
Expand Down
42 changes: 20 additions & 22 deletions src/Admin/src/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Frontend\Admin\Controller;

use Doctrine\ORM\OptimisticLockException;
use Doctrine\ORM\ORMException;
use Dot\AnnotatedServices\Annotation\Inject;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\NoResultException;
Expand All @@ -21,11 +23,13 @@
use Frontend\Admin\FormData\AdminFormData;
use Frontend\Admin\InputFilter\EditAdminInputFilter;
use Frontend\Admin\Service\AdminService;
use GeoIp2\Exception\AddressNotFoundException;
use Laminas\Authentication\AuthenticationService;
use Laminas\Authentication\AuthenticationServiceInterface;
use Laminas\Diactoros\Response\HtmlResponse;
use Laminas\Diactoros\Response\JsonResponse;
use Laminas\Diactoros\Response\RedirectResponse;
use MaxMind\Db\Reader\InvalidDatabaseException;
use Mezzio\Router\RouterInterface;
use Mezzio\Template\TemplateRendererInterface;
use Psr\Http\Message\ResponseInterface;
Expand All @@ -37,45 +41,39 @@
*/
class AdminController extends AbstractActionController
{
/** @var RouterInterface $router */
protected RouterInterface $router;

/** @var TemplateRendererInterface $template */
protected TemplateRendererInterface $template;

/** @var AdminService $adminService */
protected AdminService $adminService;

/** @var AuthenticationServiceInterface|AuthenticationService $authenticationService */
protected AuthenticationServiceInterface $authenticationService;

/** @var FlashMessenger $messenger */
protected AuthenticationService|AuthenticationServiceInterface $authenticationService;
protected FlashMessenger $messenger;

/** @var FormsPlugin $forms */
protected FormsPlugin $forms;

/** @var AdminForm $adminForm */
protected AdminForm $adminForm;

/**
* AdminController constructor.
* @param AdminService $adminService
* @param RouterInterface $router
* @param TemplateRendererInterface $template
* @param AuthenticationService $authenticationService
* @param AuthenticationServiceInterface $authenticationService
* @param FlashMessenger $messenger
* @param FormsPlugin $forms
* @param AdminForm $adminForm
*
* @Inject({AdminService::class, RouterInterface::class, TemplateRendererInterface::class,
* AuthenticationService::class, FlashMessenger::class, FormsPlugin::class, AdminForm::class})
* @Inject({
* AdminService::class,
* RouterInterface::class,
* TemplateRendererInterface::class,
* AuthenticationServiceInterface::class,
* FlashMessenger::class,
* FormsPlugin::class,
* AdminForm::class
* })
*/
public function __construct(
AdminService $adminService,
RouterInterface $router,
TemplateRendererInterface $template,
AuthenticationService $authenticationService,
AuthenticationServiceInterface $authenticationService,
FlashMessenger $messenger,
FormsPlugin $forms,
AdminForm $adminForm
Expand Down Expand Up @@ -229,10 +227,10 @@ public function manageAction(): ResponseInterface

/**
* @return ResponseInterface
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\OptimisticLockException
* @throws \GeoIp2\Exception\AddressNotFoundException
* @throws \MaxMind\Db\Reader\InvalidDatabaseException
* @throws ORMException
* @throws OptimisticLockException
* @throws AddressNotFoundException
* @throws InvalidDatabaseException
*/
public function loginAction(): ResponseInterface
{
Expand Down
24 changes: 0 additions & 24 deletions src/Admin/src/Doctrine/AdminAuthentication.php

This file was deleted.

4 changes: 2 additions & 2 deletions src/Admin/src/Entity/AdminLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

/**
* Class AdminLogin
* @ORM\Entity(repositoryClass="Frontend\Admin\Repository\AdminLoginsRepository")
* @ORM\Entity(repositoryClass="Frontend\Admin\Repository\AdminLoginRepository")
* @ORM\Table(name="admin_login")
* @ORM\HasLifecycleCallbacks()
* @package Frontend\Admin\Entity
Expand Down Expand Up @@ -124,7 +124,7 @@ class AdminLogin extends AbstractEntity
protected string $identity;

/**
* Admin constructor.
* AdminLogin constructor.
*/
public function __construct()
{
Expand Down
1 change: 0 additions & 1 deletion src/Admin/src/Form/AdminForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
class AdminForm extends Form
{
protected InputFilterInterface $inputFilter;

protected array $roles = [];

/**
Expand Down
1 change: 0 additions & 1 deletion src/Admin/src/Form/EditAdminForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
class EditAdminForm extends Form
{
protected InputFilterInterface $inputFilter;

protected array $roles = [];

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Admin/src/InputFilter/AdminInputFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ public function init()
$firstName->setRequired(false);
$firstName->getFilterChain()->attachByName(StringTrim::class);
$firstName->getValidatorChain()->attachByName(NotEmpty::class);
$firstName->getValidatorChain()->attachByName(StringLength::class);
$firstName->getFilterChain()->attachByName(StringLength::class, [
$firstName->getValidatorChain()->attachByName(StringLength::class, [
'max' => 150,
'message' => '<b>FirstName</b> must max 150 characters',
]);
Expand Down
15 changes: 15 additions & 0 deletions src/Admin/src/Repository/AdminLoginRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Frontend\Admin\Repository;

use Frontend\App\Repository\AbstractRepository;

/**
* Class AdminLoginRepository
* @package Frontend\Admin\Repository
*/
class AdminLoginRepository extends AbstractRepository
{
}
2 changes: 0 additions & 2 deletions src/Admin/src/Repository/AdminRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\NoResultException;
use Doctrine\ORM\OptimisticLockException;
use Doctrine\ORM\ORMException;
use Doctrine\ORM\QueryBuilder;
use Frontend\App\Repository\AbstractRepository;
use Frontend\Admin\Entity\Admin;
Expand Down
18 changes: 6 additions & 12 deletions src/Admin/src/Service/AdminService.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,10 @@
*/
class AdminService implements AdminServiceInterface
{
/** @var EntityManager $em */
protected EntityManager $em;

/** @var AdminRepository $adminRepository */
protected AdminRepository $adminRepository;

/** @var AdminRoleRepository $adminRoleRepository */
protected AdminRoleRepository $adminRoleRepository;

/** @var LocationServiceInterface $locationService */
protected LocationServiceInterface $locationService;

/** @var DeviceServiceInterface $deviceService */
protected DeviceServiceInterface $deviceService;

/**
Expand All @@ -53,16 +44,19 @@ class AdminService implements AdminServiceInterface
* @param DeviceServiceInterface $deviceService
* @param int $cacheLifetime
*
* @Inject({EntityManager::class, LocationServiceInterface::class, DeviceServiceInterface::class,
* "config.resultCacheLifetime"})
* @Inject({
* EntityManager::class,
* LocationServiceInterface::class,
* DeviceServiceInterface::class,
* "config.resultCacheLifetime"
* })
*/
public function __construct(
EntityManager $em,
LocationServiceInterface $locationService,
DeviceServiceInterface $deviceService,
int $cacheLifetime
) {

$this->em = $em;
$this->adminRepository = $em->getRepository(Admin::class);
$this->adminRoleRepository = $em->getRepository(AdminRole::class);
Expand Down
2 changes: 0 additions & 2 deletions src/Admin/src/Service/AdminServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
/**
* Class AdminService
* @package Frontend\Admin\Service
*
* @Service
*/
interface AdminServiceInterface
{
Expand Down
10 changes: 6 additions & 4 deletions src/App/src/Controller/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
class DashboardController extends AbstractActionController
{
protected RouterInterface $router;

protected TemplateRendererInterface $template;

protected AuthenticationServiceInterface $authenticationService;

/**
Expand All @@ -31,7 +29,11 @@ class DashboardController extends AbstractActionController
* @param TemplateRendererInterface $template
* @param AuthenticationService $authenticationService
*
* @Inject({RouterInterface::class, TemplateRendererInterface::class, AuthenticationService::class})
* @Inject({
* RouterInterface::class,
* TemplateRendererInterface::class,
* AuthenticationService::class
* })
*/
public function __construct(
RouterInterface $router,
Expand All @@ -46,7 +48,7 @@ public function __construct(
/**
* @return ResponseInterface
*/
public function indexAction()
public function indexAction(): ResponseInterface
{
return new HtmlResponse($this->template->render('app::dashboard'));
}
Expand Down
5 changes: 1 addition & 4 deletions src/App/src/Middleware/AuthMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@
class AuthMiddleware implements MiddlewareInterface
{
protected RouterInterface $router;

protected FlashMessenger $messenger;

protected GuardsProviderInterface $guardProvider;

protected RbacGuardOptions $options;

/**
* IdentityMiddleware constructor.
* AuthMiddleware constructor.
* @param RouterInterface $router
* @param FlashMessenger $messenger
* @param GuardsProviderInterface $guardProvider
Expand Down
5 changes: 1 addition & 4 deletions src/App/src/Plugin/FormsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
class FormsPlugin implements PluginInterface
{
protected FormElementManager $formElementManager;

protected ContainerInterface $container;

protected ?FlashMessengerInterface $flashMessenger;

/**
Expand All @@ -39,8 +37,7 @@ class FormsPlugin implements PluginInterface
* @param ContainerInterface $container
* @param FlashMessengerInterface|null $flashMessenger
*/
public function __construct
(
public function __construct(
FormElementManager $formManager,
ContainerInterface $container,
FlashMessengerInterface $flashMessenger = null
Expand Down
9 changes: 5 additions & 4 deletions src/App/src/Service/IpService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
class IpService
{
/**
* @return mixed
* @param array $server
* @return array|false|mixed|string
*/
public static function getUserIp(array $server)
public static function getUserIp(array $server): mixed
{
if (!empty($server)) {
// check if HTTP_X_FORWARDED_FOR is public network IP
Expand Down Expand Up @@ -39,10 +40,10 @@ public static function getUserIp(array $server)
}

/**
* @param mixed $ip
* @param $ip
* @return false|string
*/
public static function validIp($ip)
public static function validIp($ip): bool|string
{
// special cases that return private are the loopback address and IPv6 addresses
if ($ip == '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
Expand Down

0 comments on commit 23099e0

Please sign in to comment.