Format code

This commit is contained in:
Marco Petersen 2018-09-12 23:25:22 +03:00
parent 60119c5b1b
commit f1b9ffd160
40 changed files with 257 additions and 301 deletions

View File

@ -1,12 +1,11 @@
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
/**
*
* @author kevinfrantz
*
*/
interface ActivationInterface
{
@ -14,4 +13,3 @@ interface ActivationInterface
public function activate(): Response;
}

View File

@ -1,12 +1,11 @@
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
/**
*
* @author kevinfrantz
*
*/
interface CreationInterface
{
@ -14,4 +13,3 @@ interface CreationInterface
public function delete(): Response;
}

View File

@ -1,4 +1,5 @@
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@ -6,9 +7,7 @@ use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Response;
/**
*
* @author kevinfrantz
*
*/
class DefaultController extends AbstractController implements DefaultControllerInterface
{
@ -17,7 +16,7 @@ class DefaultController extends AbstractController implements DefaultControllerI
*/
public function imprint(): Response
{
return $this->render("standard/imprint.html.twig");
return $this->render('standard/imprint.html.twig');
}
/**
@ -25,7 +24,6 @@ class DefaultController extends AbstractController implements DefaultControllerI
*/
public function homepage(): Response
{
return $this->render("standard/homepage.html.twig");
return $this->render('standard/homepage.html.twig');
}
}

View File

@ -1,12 +1,11 @@
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
/**
*
* @author kevinfrantz
*
*/
interface DefaultControllerInterface
{
@ -14,4 +13,3 @@ interface DefaultControllerInterface
public function imprint(): Response;
}

View File

@ -1,15 +1,13 @@
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
/**
*
* @author kevinfrantz
*
*/
interface ModificationInterface
{
public function modify(int $id): Response;
}

View File

@ -1,4 +1,5 @@
<?php
namespace App\Controller;
use App\Form\UserType;
@ -7,22 +8,17 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Form\FormInterface;
class RegistrationController extends AbstractController
{
/**
*
* @var User
*/
private $user;
/**
*
* @Route("/register", name="user_register")
*/
public function register(Request $request, UserPasswordEncoderInterface $passwordEncoder, TranslatorInterface $translator): Response
@ -33,11 +29,13 @@ class RegistrationController extends AbstractController
if ($form->isSubmitted() && $form->isValid()) {
$this->encodePassword($passwordEncoder);
$this->saveUser($translator);
return $this->redirectToRoute('login');
}
return $this->render("user/register.html.twig", array(
'form' => $form->createView()
));
return $this->render('user/register.html.twig', [
'form' => $form->createView(),
]);
}
public function encodePassword(UserPasswordEncoderInterface $passwordEncoder): void
@ -58,4 +56,3 @@ class RegistrationController extends AbstractController
}
}
}

View File

@ -1,4 +1,5 @@
<?php
namespace App\Controller;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
@ -8,14 +9,11 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Translation\TranslatorInterface;
/**
*
* @author kevinfrantz
*
*/
class SecurityController extends AbstractController
{
/**
*
* @Route("/login", name="login")
*/
public function login(AuthenticationUtils $authenticationUtils, TranslatorInterface $translator): Response
@ -29,9 +27,9 @@ class SecurityController extends AbstractController
$this->addFlash('success', $translator->trans('User %user% loged in.', ['%user%' => $lastUsername]));
}
}
return $this->render("user/login.html.twig",[
return $this->render('user/login.html.twig', [
'last_username' => $authenticationUtils->getLastUsername(),
]);
}
}

View File

@ -1,32 +1,35 @@
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
/**
*
* @author kevinfrantz
*
*/
class SourceController implements SourceControllerInterface
{
public function modify(int $id): Response
{}
public function show(int $id): Response
{}
public function activate(): Response
{}
public function create(): Response
{}
public function delete(): Response
{}
public function deactivate(): Response
{}
{
}
public function show(int $id): Response
{
}
public function activate(): Response
{
}
public function create(): Response
{
}
public function delete(): Response
{
}
public function deactivate(): Response
{
}
}

View File

@ -1,15 +1,13 @@
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
/**
*
* @author kevinfrantz
*
*/
interface SourceControllerInterface extends CreationInterface, ActivationInterface, ModificationInterface
{
public function show(int $id): Response;
}

View File

@ -1,4 +1,5 @@
<?php
namespace App\Entity;
use App\Entity\Attribut\IdAttribut;
@ -6,8 +7,8 @@ use App\Entity\Attribut\NodeAttribut;
use Doctrine\ORM\Mapping as ORM;
/**
*
* @author kevinfrantz
*
* @see https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/inheritance-mapping.html
* @ORM\Entity
* @ORM\InheritanceType("JOINED")
@ -19,9 +20,7 @@ abstract class AbstractSource implements SourceInterface
use IdAttribut,NodeAttribut;
/**
*
* @var ConfigurationInterface
*/
protected $configuration;
}

View File

@ -1,23 +1,24 @@
<?php
namespace App\Entity\Attribut;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\NodeInterface;
/**
*
* @author kevinfrantz
*
*/
trait ChildsAttribut {
trait ChildsAttribut
{
/**
* Many Nodes have many childs
* Many Nodes have many childs.
*
* @ORM\ManyToMany(targetEntity="Node")
* @ORM\JoinTable(name="nodes_childs",
* joinColumns={@ORM\JoinColumn(name="node_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="node_id", referencedColumnName="id")}
* )
*
* @var ArrayCollection|NodeInterface[]
*/
protected $childs;
@ -31,6 +32,4 @@ trait ChildsAttribut {
{
$this->childs = $childs;
}
}

View File

@ -1,10 +1,11 @@
<?php
namespace App\Entity\Attribut;
use Doctrine\Common\Collections\ArrayCollection;
/**
*
* @author kevinfrantz
*
*/
interface ChildsAttributeInterface
{
@ -12,4 +13,3 @@ interface ChildsAttributeInterface
public function getChilds(): ArrayCollection;
}

View File

@ -1,12 +1,12 @@
<?php
namespace App\Entity\Attribut;
/**
*
* @author kevinfrantz
*
*/
trait IdAttribut {
trait IdAttribut
{
/**
* @ORM\Id
* @ORM\GeneratedValue
@ -24,4 +24,3 @@ trait IdAttribut {
return $this->id;
}
}

View File

@ -1,10 +1,9 @@
<?php
namespace App\Entity\Attribut;
/**
*
* @author kevinfrantz
*
*/
interface IdAttributInterface
{
@ -12,4 +11,3 @@ interface IdAttributInterface
public function getId(): int;
}

View File

@ -1,14 +1,14 @@
<?php
namespace App\Entity\Attribut;
use App\Entity\NodeInterface;
/**
*
* @author kevinfrantz
*
*/
trait NodeAttribut{
trait NodeAttribut
{
/**
* @var NodeInterface
* @ORM\OneToOne(targetEntity="Node")
@ -25,6 +25,4 @@ trait NodeAttribut{
{
return $this->node;
}
}

View File

@ -1,12 +1,11 @@
<?php
namespace App\Entity\Attribut;
use App\Entity\NodeInterface;
/**
*
* @author kevinfrantz
*
*/
interface NodeAttributInterface
{
@ -14,4 +13,3 @@ interface NodeAttributInterface
public function getNode(): NodeInterface;
}

View File

@ -1,24 +1,24 @@
<?php
namespace App\Entity\Attribut;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\NodeInterface;
/**
*
* @author kevinfrantz
*
*/
trait ParentAttribut {
trait ParentAttribut
{
/**
* Many Nodes have many parents
* Many Nodes have many parents.
*
* @ORM\ManyToMany(targetEntity="Node")
* @ORM\JoinTable(name="nodes_parents",
* joinColumns={@ORM\JoinColumn(name="node_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="node_id", referencedColumnName="id")}
* )
*
* @var ArrayCollection|NodeInterface[]
*/
protected $parents;
@ -33,4 +33,3 @@ trait ParentAttribut {
$this->parents = $parents;
}
}

View File

@ -1,12 +1,11 @@
<?php
namespace App\Entity\Attribut;
use Doctrine\Common\Collections\ArrayCollection;
/**
*
* @author kevinfrantz
*
*/
interface ParentsAttributInterface
{
@ -14,4 +13,3 @@ interface ParentsAttributInterface
public function getParents(): ArrayCollection;
}

View File

@ -1,12 +1,12 @@
<?php
namespace App\Entity\Attribut;
/**
*
* @author kevinfrantz
*
*/
trait PasswordAttribut {
trait PasswordAttribut
{
/**
* @ORM\Column(type="string", length=64)
*/
@ -17,8 +17,8 @@ trait PasswordAttribut {
return $this->password;
}
public function setPassword(string $password):void{
public function setPassword(string $password): void
{
$this->password = $password;
}
}

View File

@ -1,18 +1,18 @@
<?php
namespace App\Entity\Attribut;
use Symfony\Component\Validator\Constraints as Assert;
/**
*
* @author kevinfrantz
*
*/
trait PlainPasswordAttribute {
trait PlainPasswordAttribute
{
/**
*
* @Assert\NotBlank()
* @Assert\Length(max=4096)
*
* @var string
*/
private $plainPassword;
@ -27,4 +27,3 @@ trait PlainPasswordAttribute {
$this->plainPassword = $password;
}
}

View File

@ -1,27 +1,29 @@
<?php
namespace App\Entity\Attribut;
use App\Entity\SourceInterface;
/**
*
* @author kevinfrantz
*
*/
trait SourceAttribut {
trait SourceAttribut
{
/**
* @ORM\OneToOne(targetEntity="AbstractSource")
* @ORM\JoinColumn(name="source_id", referencedColumnName="id")
*
* @var SourceInterface
*/
protected $source;
public function getSource():SourceInterface{
public function getSource(): SourceInterface
{
return $this->source;
}
public function setSource(SourceInterface $source):void{
public function setSource(SourceInterface $source): void
{
$this->source = $source;
}
}

View File

@ -1,12 +1,11 @@
<?php
namespace App\Entity\Attribut;
use App\Entity\SourceInterface;
/**
*
* @author kevinfrantz
*
*/
interface SourceAttributInterface
{
@ -14,4 +13,3 @@ interface SourceAttributInterface
public function setSource(SourceInterface $source): void;
}

View File

@ -1,13 +1,14 @@
<?php
namespace App\Entity\Attribut;
/**
* This trait doesn't need an own interface because it's covered by symfony
* @author kevinfrantz
* This trait doesn't need an own interface because it's covered by symfony.
*
* @author kevinfrantz
*/
trait UsernameAttribut{
trait UsernameAttribut
{
/**
* @ORM\Column(type="string", length=25, unique=true)
*/
@ -18,8 +19,8 @@ trait UsernameAttribut{
return $this->username;
}
public function setUsername(string $username):void{
public function setUsername(string $username): void
{
$this->username = \trim($username);
}
}

View File

@ -1,48 +1,48 @@
<?php
namespace App\Entity;
/**
*
* @author kevinfrantz
*
*/
class Configuration implements ConfigurationInterface
{
/**
*
* @var PropertyInterface
*/
protected $read;
/**
*
* @var PropertyInterface
*/
protected $write;
/**
*
* @var PropertyInterface
*/
protected $administrate;
public function setAdministrate(Property $administrate): void
{}
public function getAdministrate(): Property
{}
public function setWrite(Property $write): void
{}
public function getWrite(): Property
{}
public function setRead(Property $read): void
{}
public function getRead(): Property
{}
{
}
public function getAdministrate(): Property
{
}
public function setWrite(Property $write): void
{
}
public function getWrite(): Property
{
}
public function setRead(Property $read): void
{
}
public function getRead(): Property
{
}
}

View File

@ -1,10 +1,11 @@
<?php
namespace App\Entity;
/**
* This class is not a source!
* @author kevinfrantz
*
* @author kevinfrantz
*/
interface ConfigurationInterface
{
@ -19,6 +20,4 @@ interface ConfigurationInterface
public function setAdministrate(Property $administrate): void;
public function getAdministrate(): Property;
}

View File

@ -1,4 +1,5 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
@ -8,7 +9,6 @@ use App\Entity\Attribut\ParentAttribut;
use App\Entity\Attribut\ChildsAttribut;
/**
*
* @author kevinfrantz
* @ORM\Table(name="node")
* @ORM\Entity(repositoryClass="App\Repository\NodeRepository")
@ -20,4 +20,3 @@ class Node implements NodeInterface
ParentAttribut,
ChildsAttribut;
}

View File

@ -1,4 +1,5 @@
<?php
namespace App\Entity;
use App\Entity\Attribut\SourceAttributInterface;
@ -7,10 +8,8 @@ use App\Entity\Attribut\ParentsAttributInterface;
use App\Entity\Attribut\ChildsAttributeInterface;
/**
*
* @author kevinfrantz
*
*/
interface NodeInterface extends SourceAttributInterface, IdAttributInterface, ParentsAttributInterface, ChildsAttributeInterface
{}
{
}

View File

@ -1,32 +1,29 @@
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
/**
*
* @author kevinfrantz
*
*/
class Property implements PropertyInterface
{
/**
*
* @var ArrayCollection|NodeInterface[]
*/
protected $whitelist;
/**
*
* @var ArrayCollection|NodeInterface[]
*/
protected $blacklist;
public function getLegitimated(): ArrayCollection
{}
public function isLegitimated(SourceInterface $source): bool
{}
{
}
public function isLegitimated(SourceInterface $source): bool
{
}
}

View File

@ -1,12 +1,11 @@
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
/**
*
* @author kevinfrantz
*
*/
interface PropertyInterface
{
@ -14,4 +13,3 @@ interface PropertyInterface
public function getLegitimated(): ArrayCollection;
}

View File

@ -1,15 +1,13 @@
<?php
namespace App\Entity;
use App\Entity\Attribut\NodeAttributInterface;
use App\Entity\Attribut\IdAttributInterface;
/**
*
* @author kevinfrantz
*
*/
interface SourceInterface extends IdAttributInterface, NodeAttributInterface
{
}

View File

@ -1,4 +1,5 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
@ -7,7 +8,6 @@ use App\Entity\Attribut\PasswordAttribut;
use App\Entity\Attribut\PlainPasswordAttribute;
/**
*
* @author kevinfrantz
* @ORM\Table(name="source_user")
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
@ -33,7 +33,7 @@ class User extends AbstractSource implements UserInterface
public function getRoles()
{
return array('ROLE_USER');
return ['ROLE_USER'];
}
public function eraseCredentials()
@ -43,11 +43,11 @@ class User extends AbstractSource implements UserInterface
/** @see \Serializable::serialize() */
public function serialize()
{
return serialize(array(
return serialize([
$this->id,
$this->username,
$this->password,
));
]);
}
/** @see \Serializable::unserialize() */
@ -56,7 +56,6 @@ class User extends AbstractSource implements UserInterface
list(
$this->id,
$this->username,
$this->password,
) = unserialize($serialized, array('allowed_classes' => false));
$this->password) = unserialize($serialized, ['allowed_classes' => false]);
}
}

View File

@ -1,14 +1,12 @@
<?php
namespace App\Entity;
use Symfony\Component\Security\Core\User\UserInterface as SymfonyUserInterface;
/**
*
* @author kevinfrantz
*
*/
interface UserInterface extends SymfonyUserInterface, \Serializable
{
}

View File

@ -1,11 +1,11 @@
<?php
namespace App\Form;
use App\Entity\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
@ -16,18 +16,18 @@ class UserType extends AbstractType
{
$builder
->add('username', TextType::class)
->add('plainPassword', RepeatedType::class, array(
->add('plainPassword', RepeatedType::class, [
'type' => PasswordType::class,
'first_options' => array('label' => 'Password'),
'second_options' => array('label' => 'Repeat Password'),
))
'first_options' => ['label' => 'Password'],
'second_options' => ['label' => 'Repeat Password'],
])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
$resolver->setDefaults([
'data_class' => User::class,
));
]);
}
}

View File

@ -1,4 +1,5 @@
<?php
// src/Menu/Menu.php
namespace App\Menu;
@ -11,7 +12,6 @@ use Symfony\Component\HttpFoundation\RequestStack;
class Menu
{
/**
* @var EventDispatcherInterface
*/
@ -30,11 +30,11 @@ class Menu
public function userTopbar(RequestStack $request): ItemInterface
{
$menu = $this->factory->createItem('root', array(
'childrenAttributes' => array(
$menu = $this->factory->createItem('root', [
'childrenAttributes' => [
'class' => 'navbar-nav mr-auto',
),
));
],
]);
$this->dispatcher->dispatch(
UserMenuEvent::EVENT,

View File

@ -1,14 +1,12 @@
<?php
namespace App\Repository;
use Doctrine\ORM\EntityRepository;
/**
*
* @author kevinfrantz
*
*/
class UserRepository extends EntityRepository
{
}

View File

@ -1,5 +1,7 @@
<?php
namespace App\Subscriber;
use App\Event\Menu\Topbar\UserMenuEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
@ -7,15 +9,12 @@ use Symfony\Component\Translation\TranslatorInterface;
class UserMenuSubscriber implements EventSubscriberInterface
{
/**
*
* @var TokenStorageInterface
*/
private $tokenStorage;
/**
*
* @var TranslatorInterface
*/
private $translator;
@ -95,7 +94,7 @@ class UserMenuSubscriber implements EventSubscriberInterface
public static function getSubscribedEvents(): array
{
return [
UserMenuEvent::EVENT => 'onUserMenuConfigure'
UserMenuEvent::EVENT => 'onUserMenuConfigure',
];
}
}

View File

@ -1,15 +1,13 @@
<?php
namespace App\Tests\Unit\Controller;
namespace App\Tests\Unit\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use App\Controller\DefaultControllerInterface;
use App\Controller\DefaultController;
/**
*
* @author kevinfrantz
*
*/
class DefaultControllerTest extends WebTestCase
{
@ -18,20 +16,22 @@ class DefaultControllerTest extends WebTestCase
*/
protected $defaultController;
public function setUp():void{
public function setUp(): void
{
$this->defaultController = new DefaultController();
}
public function testHomepage():void{
public function testHomepage(): void
{
$client = static::createClient();
$client->request('GET', '/');
$this->assertEquals(200, $client->getResponse()->getStatusCode());
}
public function testImprint():void{
public function testImprint(): void
{
$client = static::createClient();
$client->request('GET', '/imprint');
$this->assertEquals(200, $client->getResponse()->getStatusCode());
}
}

View File

@ -1,4 +1,5 @@
<?php
namespace App\Tests\Unit\Controller;
use App\Controller\UserController;
@ -6,19 +7,17 @@ use App\Controller\UserControllerInterface;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
/**
*
* @author kevinfrantz
*
*/
class UserControllerTest extends WebTestCase
{
/**
*
* @var UserControllerInterface
*/
protected $userController;
public function setUp():void{
public function setUp(): void
{
$this->userController = new UserController();
}
@ -43,4 +42,3 @@ class UserControllerTest extends WebTestCase
$this->assertEquals(200, $client->getResponse()->getStatusCode());
}
}

View File

@ -1,13 +1,12 @@
<?php
namespace tests\unit\Entity;
use PHPUnit\Framework\TestCase;
use App\Entity\User;
/**
*
* @author kevinfrantz
*
*/
class UserTest extends TestCase
{
@ -16,23 +15,24 @@ class UserTest extends TestCase
const USERNAME = 'tester';
/**
*
* @var User
*/
protected $user;
public function setUp():void{
public function setUp(): void
{
$this->user = new User();
$this->user->setPassword(self::PASSWORD);
$this->user->setUsername(' '.self::USERNAME.' ');
}
public function testUsername():void{
public function testUsername(): void
{
$this->assertEquals(self::USERNAME, $this->user->getUsername());
}
public function testPassword():void{
public function testPassword(): void
{
$this->assertEquals(self::PASSWORD, $this->user->getPassword());
}
}