Used PHP_CS_Fixer with symfony preset on codebase.

This commit is contained in:
Jan Böhmer 2019-03-20 23:16:07 +01:00
parent 0f3ba9b6a8
commit e2f7aafa2d
43 changed files with 971 additions and 1068 deletions

View file

@ -1,9 +1,8 @@
<?php
/**
*
* part-db version 0.1
* Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/
* http://www.cl-projects.de/.
*
* part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -26,34 +25,32 @@
* 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\Services;
use Symfony\Component\Asset\Packages;
class AttachmentFilenameService
{
protected $package;
protected $package;
public function __construct(Packages $package)
{
$this->package = $package;
}
public function attachmentPathToAbsolutePath(?string $filename) : ?string
public function attachmentPathToAbsolutePath(?string $filename): ?string
{
//Return placeholder if a part does not have an attachment
if ($filename == null) {
if (null == $filename) {
return $this->package->getUrl('/img/part_placeholder.svg');
}
if (stripos($filename, "%BASE%/img/") !== false) {
if (false !== stripos($filename, '%BASE%/img/')) {
return $this->package->getUrl(str_replace('%BASE%', '', $filename));
}
//If no other method works, return placeholder
return $this->package->getUrl('/img/part_placeholder.svg');
}
}
}

View file

@ -1,9 +1,8 @@
<?php
/**
*
* part-db version 0.1
* Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/
* http://www.cl-projects.de/.
*
* part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -26,17 +25,13 @@
* 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\Services;
use App\Entity\DBElement;
use App\Entity\NamedDBElement;
use App\Entity\Part;
use App\Exceptions\EntityNotSupported;
use Doctrine\Migrations\Finder\Exception\NameIsReserved;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
class EntityURLGenerator
@ -53,15 +48,16 @@ class EntityURLGenerator
/**
* Generates an URL to a page, where info about this entity can be viewed.
*
* @param $entity mixed The entity for which the info should be generated.
*
* @return string The URL to the info page
*
* @throws EntityNotSupported If the method is not supported for the given Entity
*/
public function infoURL($entity) : string
public function infoURL($entity): string
{
if($entity instanceof Part)
{
if ($entity instanceof Part) {
return $this->urlGenerator->generate('part_info', ['id' => $entity->getID()]);
}
@ -69,10 +65,9 @@ class EntityURLGenerator
throw new EntityNotSupported('The given entity is not supported yet!');
}
public function editURL($entity) : string
public function editURL($entity): string
{
if($entity instanceof Part)
{
if ($entity instanceof Part) {
return $this->urlGenerator->generate('part_edit', ['id' => $entity->getID()]);
}
@ -80,20 +75,18 @@ class EntityURLGenerator
throw new EntityNotSupported('The given entity is not supported yet!');
}
public function createURL($entity) : string
public function createURL($entity): string
{
if($entity instanceof Part)
{
if ($entity instanceof Part) {
return $this->urlGenerator->generate('part_new');
}
throw new EntityNotSupported('The given entity is not supported yet!');
}
public function cloneURL($entity) : string
public function cloneURL($entity): string
{
if($entity instanceof Part)
{
if ($entity instanceof Part) {
return $this->urlGenerator->generate('part_clone', ['id' => $entity->getID()]);
}
@ -102,20 +95,19 @@ class EntityURLGenerator
/**
* Generates an HTML link to the info page about the given entity.
*
* @param $entity mixed The entity for which the info link should be generated.
*
* @return string The HTML of the info page link
*
* @throws EntityNotSupported
*/
public function infoHTML($entity) : string
public function infoHTML($entity): string
{
$href = $this->infoURL($entity);
if($entity instanceof NamedDBElement)
{
if ($entity instanceof NamedDBElement) {
return sprintf('<a href="%s">%s</a>', $href, $entity->getName());
}
}
}
}

View file

@ -1,9 +1,8 @@
<?php
/**
*
* part-db version 0.1
* Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/
* http://www.cl-projects.de/.
*
* part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -26,12 +25,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\Services;
use App\Configuration\PermissionsConfiguration;
use App\Entity\User;
use App\Security\Interfaces\HasPermissionsInterface;
@ -43,20 +40,18 @@ class PermissionResolver
{
protected $permission_structure;
/**
*
* PermissionResolver constructor.
*
* @param ParameterBagInterface $params
*/
public function __construct(ParameterBagInterface $params)
{
//Read the permission config file...
$config = Yaml::parse(
file_get_contents(__DIR__ . '/../../config/permissions.yaml')
file_get_contents(__DIR__.'/../../config/permissions.yaml')
);
$configs = [$config];
//... And parse it
@ -72,19 +67,19 @@ class PermissionResolver
//dump($this->permission_structure);
}
/**
* Check if a user/group is allowed to do the specified operation for the permission.
*
* See permissions.yaml for valid permission operation combinations.
*
* @param HasPermissionsInterface $user The user/group for which the operation should be checked.
* @param string $permission The name of the permission for which should be checked.
* @param string $operation The name of the operation for which should be checked.
* @param HasPermissionsInterface $user The user/group for which the operation should be checked.
* @param string $permission The name of the permission for which should be checked.
* @param string $operation The name of the operation for which should be checked.
*
* @return bool|null True, if the user is allowed to do the operation (ALLOW), false if not (DISALLOW), and null,
* if the value is set to inherit.
* if the value is set to inherit.
*/
public function dontInherit(HasPermissionsInterface $user, string $permission, string $operation) : ?bool
public function dontInherit(HasPermissionsInterface $user, string $permission, string $operation): ?bool
{
//Get the permissions from the user
$perm_list = $user->getPermissions();
@ -95,7 +90,6 @@ class PermissionResolver
return $perm_list->getPermissionValue($permission, $bit);
}
/**
* Checks if a user is allowed to do the specified operation for the permission.
* In contrast to dontInherit() it tries to resolve the inherit values, of the user, by going upwards in the
@ -104,27 +98,28 @@ class PermissionResolver
*
* In that case the voter should set it manually to false by using ?? false.
*
* @param User $user The user for which the operation should be checked.
* @param User $user The user for which the operation should be checked.
* @param string $permission The name of the permission for which should be checked.
* @param string $operation The name of the operation for which should be checked.
* @param string $operation The name of the operation for which should be checked.
*
* @return bool|null True, if the user is allowed to do the operation (ALLOW), false if not (DISALLOW), and null,
* if the value is set to inherit.
* if the value is set to inherit.
*/
public function inherit(User $user, string $permission, string $operation) : ?bool
public function inherit(User $user, string $permission, string $operation): ?bool
{
//Check if we need to inherit
$allowed = $this->dontInherit($user, $permission, $operation);
if ($allowed !== null) {
if (null !== $allowed) {
//Just return the value of the user.
return $allowed;
}
$parent = $user->getGroup();
while($parent != null){ //The top group, has parent == null
while (null != $parent) { //The top group, has parent == null
//Check if our current element gives a info about disallow/allow
$allowed = $this->dontInherit($parent, $permission, $operation);
if ($allowed !== null) {
if (null !== $allowed) {
return $allowed;
}
//Else go up in the hierachy.
@ -134,7 +129,6 @@ class PermissionResolver
return null; //The inherited value is never resolved. Should be treat as false, in Voters.
}
/**
* Lists the names of all operations that is supported for the given permission.
*
@ -143,9 +137,10 @@ class PermissionResolver
* This function is useful for the support() function of the voters.
*
* @param string $permission The permission for which the
*
* @return string[] A list of all operations that are supported by the given
*/
public function listOperationsForPermission(string $permission) : array
public function listOperationsForPermission(string $permission): array
{
$operations = $this->permission_structure['perms'][$permission]['operations'];
@ -156,9 +151,10 @@ class PermissionResolver
* Checks if the permission with the given name is existing.
*
* @param string $permission The name of the permission which we want to check.
*
* @return bool True if a perm with that name is existing. False if not.
*/
public function isValidPermission(string $permission) : bool
public function isValidPermission(string $permission): bool
{
return isset($this->permission_structure['perms'][$permission]);
}
@ -167,14 +163,13 @@ class PermissionResolver
* Checks if the permission operation combination with the given names is existing.
*
* @param string $permission The name of the permission which should be checked.
* @param string $operation The name of the operation which should be checked.
* @param string $operation The name of the operation which should be checked.
*
* @return bool True if the given permission operation combination is existing.
*/
public function isValidOperation(string $permission, string $operation) : bool
public function isValidOperation(string $permission, string $operation): bool
{
return $this->isValidPermission($permission) &&
isset($this->permission_structure['perms'][$permission]['operations'][$operation]);
}
}
}