code-cleanup: removed unused classes, added role constants, phpcs fixes (#96)

This commit is contained in:
Kevin Papst
2018-01-16 23:56:55 +01:00
committed by GitHub
parent 0a65965187
commit 7df21f3f5a
13 changed files with 35 additions and 118 deletions

View File

@@ -202,5 +202,4 @@ trait TimesheetControllerTrait
* @return \Symfony\Component\Form\FormInterface
*/
abstract protected function getEditForm(Timesheet $entry, $page);
}

View File

@@ -1,5 +1,14 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* 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 <kevin@kevinpapst.de>
*/
class Configuration implements ConfigurationInterface
{

View File

@@ -1,37 +0,0 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* 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 <kevin@kevinpapst.de>
*/
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);
}
}

View File

@@ -1,65 +0,0 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Configuration
*
* @ORM\Table(name="configuration")
* @ORM\Entity
*/
class Configuration
{
/**
* @var string
*
* @ORM\Column(name="option", type="string", length=255)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $option;
/**
* @var string
*
* @ORM\Column(name="value", type="string", length=255, nullable=false)
*/
private $value;
/**
* Set value
*
* @param string $value
*
* @return Configuration
*/
public function setValue($value)
{
$this->value = $value;
return $this;
}
/**
* Get value
*
* @return string
*/
public function getValue()
{
return $this->value;
}
/**
* Get option
*
* @return string
*/
public function getOption()
{
return $this->option;
}
}

View File

@@ -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

View File

@@ -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())

View File

@@ -36,5 +36,4 @@ class TimesheetAdminForm extends TimesheetEditForm
])
;
}
}

View File

@@ -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')

View File

@@ -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')

View File

@@ -67,5 +67,4 @@ class ActivityQuery extends VisibilityQuery
$this->project = $project;
return $this;
}
}

View File

@@ -168,5 +168,4 @@ class BaseQuery
$this->hiddenEntity = $hiddenEntity;
return $this;
}
}

View File

@@ -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}

View File

@@ -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;
}