Added an PHP CS fixer config file and applied it to files.

We now use the same the same style as the symfony project, and it allows us to simply fix the style by executing php_cs_fixer fix in the project root.
This commit is contained in:
Jan Böhmer 2019-11-09 00:47:20 +01:00
parent 89258bc102
commit e557bdedd5
210 changed files with 2099 additions and 2742 deletions

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,19 +17,15 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
/**
* @Annotation
* @package App\Validator\Constraints
*/
class AllowedFileExtension extends Constraint
{
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Validator\Constraints;
use App\Entity\Attachments\Attachment;
use App\Services\Attachments\FileTypeFilterTools;
use Symfony\Component\Form\FormInterface;
@ -33,7 +31,6 @@ use Symfony\Component\Validator\Exception\UnexpectedTypeException;
class AllowedFileExtensionValidator extends ConstraintValidator
{
protected $filterTools;
public function __construct(FileTypeFilterTools $filterTools)
@ -44,7 +41,7 @@ class AllowedFileExtensionValidator extends ConstraintValidator
/**
* Checks if the passed value is valid.
*
* @param mixed $value The value that should be validated
* @param mixed $value The value that should be validated
* @param Constraint $constraint The constraint for the validation
*/
public function validate($value, Constraint $constraint)
@ -66,7 +63,7 @@ class AllowedFileExtensionValidator extends ConstraintValidator
$attachment_type = $attachment->getAttachmentType();
//Only validate if the attachment type has specified an filetype filter:
if ($attachment_type === null || empty($attachment_type->getFiletypeFilter())) {
if (null === $attachment_type || empty($attachment_type->getFiletypeFilter())) {
return;
}
@ -76,7 +73,6 @@ class AllowedFileExtensionValidator extends ConstraintValidator
)) {
$this->context->buildViolation('validator.file_ext_not_allowed')->addViolation();
}
}
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,20 +17,18 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
/**
* This constraint restricts a user in that way that it can not lock itself out of the user system
* @package App\Validator\Constraints
* This constraint restricts a user in that way that it can not lock itself out of the user system.
*
* @Annotation
*/
class NoLockout extends Constraint
{
public $message = "validator.noLockout";
}
public $message = 'validator.noLockout';
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,18 +17,14 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Validator\Constraints;
use App\Entity\UserSystem\Group;
use App\Entity\UserSystem\User;
use App\Services\PermissionResolver;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\Entity;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Validator\Constraint;
@ -36,7 +32,6 @@ use Symfony\Component\Validator\ConstraintValidator;
class NoLockoutValidator extends ConstraintValidator
{
protected $resolver;
protected $perm_structure;
protected $security;
@ -53,7 +48,7 @@ class NoLockoutValidator extends ConstraintValidator
/**
* Checks if the passed value is valid.
*
* @param mixed $value The value that should be validated
* @param mixed $value The value that should be validated
* @param Constraint $constraint The constraint for the validation
*/
public function validate($value, Constraint $constraint)
@ -62,24 +57,22 @@ class NoLockoutValidator extends ConstraintValidator
throw new UnexpectedTypeException($constraint, NoLockout::class);
}
$perm_holder = $value;
//Prevent that a user revokes its own change_permission perm (prevent the user to lock out itself)
if ($perm_holder instanceof User || $perm_holder instanceof Group) {
$user = $this->security->getUser();
if ($user === null) {
if (null === $user) {
$user = $this->entityManager->getRepository(User::class)->getAnonymousUser();
}
if ($user instanceof User) {
//Check if we the change_permission permission has changed from allow to disallow
if (($this->resolver->inherit($user, 'users', 'edit_permissions') ?? false) === false) {
if (false === ($this->resolver->inherit($user, 'users', 'edit_permissions') ?? false)) {
$this->context->addViolation($constraint->message);
}
}
}
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Validator\Constraints;
@ -29,7 +28,6 @@ use Symfony\Component\Validator\Constraint;
* of its children can be assigned.
*
* @Annotation
* @package App\Validator\Constraints
*/
class NoneOfItsChildren extends Constraint
{
@ -42,4 +40,4 @@ class NoneOfItsChildren extends Constraint
{
return parent::validatedBy(); // TODO: Change the autogenerated stub
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,30 +17,25 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Validator\Constraints;
use App\Entity\Base\StructuralDBElement;
use Symfony\Bundle\MakerBundle\Str;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Component\Validator\Exception\UnexpectedValueException;
/**
* The validator for the NoneOfItsChildren annotation.
* @package App\Validator\Constraints
*/
class NoneOfItsChildrenValidator extends ConstraintValidator
{
/**
* Checks if the passed value is valid.
*
* @param mixed $value The value that should be validated
* @param mixed $value The value that should be validated
* @param Constraint $constraint The constraint for the validation
*/
public function validate($value, Constraint $constraint)
@ -67,7 +62,7 @@ class NoneOfItsChildrenValidator extends ConstraintValidator
// Check if the targeted parent is the object itself:
$entity_id = $entity->getID();
if ($entity_id !== null && $entity_id === $value->getID()) {
if (null !== $entity_id && $entity_id === $value->getID()) {
//Set the entity to a valid state
$entity->setParent(null);
$this->context->buildViolation($constraint->self_message)->addViolation();
@ -80,7 +75,8 @@ class NoneOfItsChildrenValidator extends ConstraintValidator
//Set the entity to a valid state
$entity->setParent(null);
$this->context->buildViolation($constraint->children_message)->addViolation();
return;
}
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,22 +17,19 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
/**
* If a property is marked with this constraint, the choosen value (of type StructuralDBElement)
* must NOT be marked as not selectable.
*
* @package App\Validator\Constraints
* @Annotation
*/
class Selectable extends Constraint
{
public $message = 'validator.isSelectable';
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Validator\Constraints;
@ -30,15 +29,13 @@ use Symfony\Component\Validator\Exception\UnexpectedValueException;
/**
* The validator for the Selectable constraint.
* @package App\Validator\Constraints
*/
class SelectableValidator extends ConstraintValidator
{
/**
* Checks if the passed value is valid.
*
* @param mixed $value The value that should be validated
* @param mixed $value The value that should be validated
* @param \Symfony\Component\Validator\Constraint $constraint The constraint for the validation
*/
public function validate($value, Constraint $constraint)
@ -66,4 +63,4 @@ class SelectableValidator extends ConstraintValidator
->addViolation();
}
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,22 +17,20 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Validator\Constraints;
use App\Entity\Attachments\Attachment;
use Symfony\Component\Validator\Constraints\Url;
/**
* Constraints the field that way that the content is either a url or a path to a builtin ressource (like %FOOTPRINTS%)
* @package App\Validator\Constraints
* Constraints the field that way that the content is either a url or a path to a builtin ressource (like %FOOTPRINTS%).
*
* @Annotation
*/
class UrlOrBuiltin extends Url
{
/** @var array A list of the placeholders that are treated as builtin */
public $allowed_placeholders = Attachment::BUILTIN_PLACEHOLDER;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\UrlValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
@ -32,7 +30,6 @@ use Symfony\Component\Validator\Exception\UnexpectedValueException;
* The validator for UrlOrBuiltin.
* It checks if the value is either a builtin ressource or a valid url.
* In both cases it is not checked, if the ressource is really existing.
* @package App\Validator\Constraints
*/
class UrlOrBuiltinValidator extends UrlValidator
{
@ -56,12 +53,10 @@ class UrlOrBuiltinValidator extends UrlValidator
//After the %PLACEHOLDER% comes a slash, so we can check if we have a placholder via explode
$tmp = explode('/', $value);
//Builtins must have a %PLACEHOLDER% construction
if (!empty($tmp) && in_array($tmp[0], $constraint->allowed_placeholders, false)) {
if (!empty($tmp) && \in_array($tmp[0], $constraint->allowed_placeholders, false)) {
return;
}
parent::validate($value, $constraint); // TODO: Change the autogenerated stub
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,19 +17,15 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
/**
* @Annotation
* @package App\Validator\Constraints
*/
class ValidFileFilter extends Constraint
{
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Validator\Constraints;
use App\Services\Attachments\FileTypeFilterTools;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
@ -31,7 +29,6 @@ use Symfony\Component\Validator\Exception\UnexpectedValueException;
class ValidFileFilterValidator extends ConstraintValidator
{
protected $filterTools;
public function __construct(FileTypeFilterTools $filterTools)
@ -42,7 +39,7 @@ class ValidFileFilterValidator extends ConstraintValidator
/**
* Checks if the passed value is valid.
*
* @param mixed $value The value that should be validated
* @param mixed $value The value that should be validated
* @param Constraint $constraint The constraint for the validation
*/
public function validate($value, Constraint $constraint)
@ -55,7 +52,7 @@ class ValidFileFilterValidator extends ConstraintValidator
return;
}
if (!is_string($value)) {
if (!\is_string($value)) {
// throw this exception if your validator cannot handle the passed type so that it can be marked as invalid
throw new UnexpectedValueException($value, 'string');
}
@ -65,4 +62,4 @@ class ValidFileFilterValidator extends ConstraintValidator
->addViolation();
}
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Validator\Constraints;
@ -26,9 +25,8 @@ use Symfony\Component\Validator\Constraint;
/**
* A constraint "dummy" to validate the PartLot.
* We need to access services in our Validator, so we can not use a simple callback on PartLot
* We need to access services in our Validator, so we can not use a simple callback on PartLot.
*
* @package App\Validator\Constraints
* @Annotation
*/
class ValidPartLot extends Constraint
@ -37,4 +35,4 @@ class ValidPartLot extends Constraint
{
return self::CLASS_CONSTRAINT;
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,15 +17,12 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Validator\Constraints;
use App\Entity\Parts\PartLot;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\DependencyInjection\Compiler\ValidateEnvPlaceholdersPass;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
@ -42,7 +39,7 @@ class ValidPartLotValidator extends ConstraintValidator
/**
* Checks if the passed value is valid.
*
* @param mixed $value The value that should be validated
* @param mixed $value The value that should be validated
* @param Constraint $constraint The constraint for the validation
*/
public function validate($value, Constraint $constraint)
@ -77,7 +74,6 @@ class ValidPartLotValidator extends ConstraintValidator
}
}
//Check for onlyExisting
if ($value->getStorageLocation()->isLimitToExistingParts()) {
if (!$parts->contains($value->getPart())) {
@ -95,4 +91,4 @@ class ValidPartLotValidator extends ConstraintValidator
}
}
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,21 +17,18 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
/**
* A PermissionEmbed object with this annotation will be checked with ValidPermissionValidator.
* That means the alsoSet values of the permission operations are set.
*
* @Annotation
* @package App\Validator\Constraints
*/
class ValidPermission extends Constraint
{
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,14 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Validator\Constraints;
use App\Entity\Parts\PartLot;
use App\Entity\UserSystem\PermissionsEmbed;
use App\Security\Interfaces\HasPermissionsInterface;
use App\Services\PermissionResolver;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
@ -33,7 +29,6 @@ use Symfony\Component\Validator\ConstraintValidator;
class ValidPermissionValidator extends ConstraintValidator
{
protected $resolver;
protected $perm_structure;
@ -46,7 +41,7 @@ class ValidPermissionValidator extends ConstraintValidator
/**
* Checks if the passed value is valid.
*
* @param mixed $value The value that should be validated
* @param mixed $value The value that should be validated
* @param Constraint $constraint The constraint for the validation
*/
public function validate($value, Constraint $constraint)
@ -62,7 +57,7 @@ class ValidPermissionValidator extends ConstraintValidator
foreach ($this->perm_structure['perms'] as $perm_key => $permission) {
foreach ($permission['operations'] as $op_key => $op) {
if (!empty($op['alsoSet']) &&
$this->resolver->dontInherit($perm_holder, $perm_key, $op_key) === true) {
true === $this->resolver->dontInherit($perm_holder, $perm_key, $op_key)) {
//Set every op listed in also Set
foreach ($op['alsoSet'] as $set_also) {
$this->resolver->setPermission($perm_holder, $perm_key, $set_also, true);
@ -71,4 +66,4 @@ class ValidPermissionValidator extends ConstraintValidator
}
}
}
}
}