From 7df21f3f5a1a6ba499e185d707627ca4f2fd3dba Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Tue, 16 Jan 2018 23:56:55 +0100 Subject: [PATCH] code-cleanup: removed unused classes, added role constants, phpcs fixes (#96) --- src/Controller/TimesheetControllerTrait.php | 1 - src/DependencyInjection/Configuration.php | 11 +++- src/DependencyInjection/KimaiExtension.php | 37 ----------- src/Entity/Configuration.php | 65 -------------------- src/Entity/User.php | 7 ++- src/EventListener/NavbarShowUserListener.php | 6 -- src/Form/TimesheetAdminForm.php | 1 - src/Repository/CustomerRepository.php | 5 +- src/Repository/ProjectRepository.php | 4 +- src/Repository/Query/ActivityQuery.php | 1 - src/Repository/Query/BaseQuery.php | 1 - src/Validator/Constraints/RoleValidator.php | 12 +++- src/Voter/ActivityVoter.php | 2 +- 13 files changed, 35 insertions(+), 118 deletions(-) delete mode 100644 src/DependencyInjection/KimaiExtension.php delete mode 100644 src/Entity/Configuration.php diff --git a/src/Controller/TimesheetControllerTrait.php b/src/Controller/TimesheetControllerTrait.php index c3e925c7..f47ee069 100644 --- a/src/Controller/TimesheetControllerTrait.php +++ b/src/Controller/TimesheetControllerTrait.php @@ -202,5 +202,4 @@ trait TimesheetControllerTrait * @return \Symfony\Component\Form\FormInterface */ abstract protected function getEditForm(Timesheet $entry, $page); - } diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index f34c28c4..3bf6606a 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace App\DependencyInjection; use Symfony\Component\Config\Definition\Builder\TreeBuilder; @@ -8,7 +17,7 @@ use Symfony\Component\Config\Definition\ConfigurationInterface; /** * This is the class that validates and merges configuration from your app/config files * - * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class} + * @author Kevin Papst */ class Configuration implements ConfigurationInterface { diff --git a/src/DependencyInjection/KimaiExtension.php b/src/DependencyInjection/KimaiExtension.php deleted file mode 100644 index c5876b56..00000000 --- a/src/DependencyInjection/KimaiExtension.php +++ /dev/null @@ -1,37 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace App\DependencyInjection; - -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Extension\Extension; -use \Doctrine\Common\ClassLoader; - -/** - * Main extension class - * - * @author Kevin Papst - */ -class KimaiExtension extends Extension -{ - - public function load(array $configs, ContainerBuilder $container) - { - $rootDir = realpath($container->getParameter('kernel.root_dir')); - $extensionsDir = realpath($rootDir . '/../vendor/beberlei/DoctrineExtensions/src/'); - - $classLoader = new ClassLoader('DoctrineExtensions', $extensionsDir); - $classLoader->register(); - - $kimaiConfig = new Configuration(); - $this->processConfiguration($kimaiConfig, $configs); - } -} diff --git a/src/Entity/Configuration.php b/src/Entity/Configuration.php deleted file mode 100644 index ef7e41db..00000000 --- a/src/Entity/Configuration.php +++ /dev/null @@ -1,65 +0,0 @@ -value = $value; - - return $this; - } - - /** - * Get value - * - * @return string - */ - public function getValue() - { - return $this->value; - } - - /** - * Get option - * - * @return string - */ - public function getOption() - { - return $this->option; - } -} diff --git a/src/Entity/User.php b/src/Entity/User.php index 1e1716a5..a01b2337 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -30,7 +30,12 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; class User implements UserInterface, AdvancedUserInterface { - const DEFAULT_ROLE = 'ROLE_USER'; + const ROLE_CUSTOMER = 'ROLE_CUSTOMER'; + const ROLE_USER = 'ROLE_USER'; + const ROLE_TEAMLEAD = 'ROLE_TEAMLEAD'; + const ROLE_ADMIN = 'ROLE_ADMIN'; + const ROLE_SUPER_ADMIN = 'ROLE_SUPER_ADMIN'; + const DEFAULT_ROLE = self::ROLE_USER; /** * @var int diff --git a/src/EventListener/NavbarShowUserListener.php b/src/EventListener/NavbarShowUserListener.php index 5ab88110..79bec296 100644 --- a/src/EventListener/NavbarShowUserListener.php +++ b/src/EventListener/NavbarShowUserListener.php @@ -45,12 +45,6 @@ class NavbarShowUserListener /* @var $myUser User */ $myUser = $this->storage->getToken()->getUser(); - $titles = []; - $roles = $this->storage->getToken()->getRoles(); - foreach ($roles as $role) { - $titles[] = ucfirst(strtolower(str_replace('ROLE_', '', $role->getRole()))); - } - $user = new UserModel(); $user->setName($myUser->getAlias() ?: $myUser->getUsername()) ->setUsername($myUser->getUsername()) diff --git a/src/Form/TimesheetAdminForm.php b/src/Form/TimesheetAdminForm.php index a49274e6..fc51ca46 100644 --- a/src/Form/TimesheetAdminForm.php +++ b/src/Form/TimesheetAdminForm.php @@ -36,5 +36,4 @@ class TimesheetAdminForm extends TimesheetEditForm ]) ; } - } diff --git a/src/Repository/CustomerRepository.php b/src/Repository/CustomerRepository.php index 157fe6ed..041f5335 100644 --- a/src/Repository/CustomerRepository.php +++ b/src/Repository/CustomerRepository.php @@ -63,7 +63,10 @@ class CustomerRepository extends AbstractRepository { $qb = $this->getEntityManager()->createQueryBuilder(); - $qb->select('COUNT(t.id) as recordAmount', 'SUM(t.duration) as recordDuration, COUNT(DISTINCT(a.id)) as activityAmount, COUNT(DISTINCT(p.id)) as projectAmount') + $qb->select('COUNT(t.id) as recordAmount') + ->addSelect('SUM(t.duration) as recordDuration') + ->addSelect('COUNT(DISTINCT(a.id)) as activityAmount') + ->addSelect('COUNT(DISTINCT(p.id)) as projectAmount') ->from(Timesheet::class, 't') ->join(Activity::class, 'a') ->join(Project::class, 'p') diff --git a/src/Repository/ProjectRepository.php b/src/Repository/ProjectRepository.php index 63107ca6..01b1ccbe 100644 --- a/src/Repository/ProjectRepository.php +++ b/src/Repository/ProjectRepository.php @@ -62,7 +62,9 @@ class ProjectRepository extends AbstractRepository { $qb = $this->getEntityManager()->createQueryBuilder(); - $qb->select('COUNT(t.id) as recordAmount', 'SUM(t.duration) as recordDuration, COUNT(DISTINCT(a.id)) as activityAmount') + $qb->select('COUNT(t.id) as recordAmount') + ->addSelect('SUM(t.duration) as recordDuration') + ->addSelect('COUNT(DISTINCT(a.id)) as activityAmount') ->from(Activity::class, 'a') ->join(Timesheet::class, 't') ->where('a.project = :project') diff --git a/src/Repository/Query/ActivityQuery.php b/src/Repository/Query/ActivityQuery.php index bdd388b4..8d61d80d 100644 --- a/src/Repository/Query/ActivityQuery.php +++ b/src/Repository/Query/ActivityQuery.php @@ -67,5 +67,4 @@ class ActivityQuery extends VisibilityQuery $this->project = $project; return $this; } - } diff --git a/src/Repository/Query/BaseQuery.php b/src/Repository/Query/BaseQuery.php index 02c6f19b..27460d78 100644 --- a/src/Repository/Query/BaseQuery.php +++ b/src/Repository/Query/BaseQuery.php @@ -168,5 +168,4 @@ class BaseQuery $this->hiddenEntity = $hiddenEntity; return $this; } - } diff --git a/src/Validator/Constraints/RoleValidator.php b/src/Validator/Constraints/RoleValidator.php index b89f4aa9..a7481644 100644 --- a/src/Validator/Constraints/RoleValidator.php +++ b/src/Validator/Constraints/RoleValidator.php @@ -11,6 +11,7 @@ namespace App\Validator\Constraints; +use App\Entity\User; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; use Symfony\Component\Validator\Exception\UnexpectedTypeException; @@ -21,7 +22,16 @@ use Symfony\Component\Validator\Exception\UnexpectedTypeException; class RoleValidator extends ConstraintValidator { - protected $allowedRoles = ['ROLE_CUSTOMER', 'ROLE_USER', 'ROLE_TEAMLEAD', 'ROLE_ADMIN', 'ROLE_SUPER_ADMIN']; + /** + * @var string[] + */ + protected $allowedRoles = [ + User::ROLE_CUSTOMER, + User::ROLE_USER, + User::ROLE_TEAMLEAD, + User::ROLE_ADMIN, + User::ROLE_SUPER_ADMIN + ]; /** * {@inheritdoc} diff --git a/src/Voter/ActivityVoter.php b/src/Voter/ActivityVoter.php index 9bf70fda..66bc1412 100644 --- a/src/Voter/ActivityVoter.php +++ b/src/Voter/ActivityVoter.php @@ -34,7 +34,7 @@ class ActivityVoter extends AbstractVoter */ protected function supports($attribute, $subject) { - if (!in_array($attribute, array(self::VIEW, self::EDIT, self::DELETE))) { + if (!in_array($attribute, array(self::VIEW, self::EDIT, self::DELETE))) { return false; }