mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-11-04 11:17:58 +00:00 
			
		
		
		
	Optimized layer attribut
This commit is contained in:
		@@ -2,21 +2,37 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace App\Entity\Attribut;
 | 
					namespace App\Entity\Attribut;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use App\DBAL\Types\Meta\Right\LayerType;
 | 
				
			||||||
 | 
					use App\Exception\NoValidChoiceException;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * @author kevinfrantz
 | 
					 * @author kevinfrantz
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
trait LayerAttribut
 | 
					trait LayerAttribut
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 | 
					     * @see LayerType
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
     * @var string
 | 
					     * @var string
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    protected $layer;
 | 
					    protected $layer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * @param string $layer
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @throws NoValidChoiceException
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
    public function setLayer(string $layer): void
 | 
					    public function setLayer(string $layer): void
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					        if (!array_key_exists($layer, LayerType::getChoices())) {
 | 
				
			||||||
 | 
					            throw new NoValidChoiceException();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        $this->layer = $layer;
 | 
					        $this->layer = $layer;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * @return string
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
    public function getLayer(): string
 | 
					    public function getLayer(): string
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return $this->layer;
 | 
					        return $this->layer;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,7 +6,6 @@ use App\Entity\Attribut\CrudAttribut;
 | 
				
			|||||||
use Doctrine\ORM\Mapping as ORM;
 | 
					use Doctrine\ORM\Mapping as ORM;
 | 
				
			||||||
use Fresh\DoctrineEnumBundle\Validator\Constraints as DoctrineAssert;
 | 
					use Fresh\DoctrineEnumBundle\Validator\Constraints as DoctrineAssert;
 | 
				
			||||||
use App\Entity\Attribut\LawAttribut;
 | 
					use App\Entity\Attribut\LawAttribut;
 | 
				
			||||||
use App\DBAL\Types\Meta\Right\LayerType;
 | 
					 | 
				
			||||||
use App\Entity\Attribut\GrantAttribut;
 | 
					use App\Entity\Attribut\GrantAttribut;
 | 
				
			||||||
use App\Logic\Operation\OperationInterface;
 | 
					use App\Logic\Operation\OperationInterface;
 | 
				
			||||||
use App\Entity\Attribut\ConditionAttribut;
 | 
					use App\Entity\Attribut\ConditionAttribut;
 | 
				
			||||||
@@ -15,8 +14,6 @@ use App\Entity\Attribut\LayerAttribut;
 | 
				
			|||||||
use App\Entity\Attribut\RelationAttribut;
 | 
					use App\Entity\Attribut\RelationAttribut;
 | 
				
			||||||
use App\Entity\Attribut\PriorityAttribut;
 | 
					use App\Entity\Attribut\PriorityAttribut;
 | 
				
			||||||
use App\Entity\Source\SourceInterface;
 | 
					use App\Entity\Source\SourceInterface;
 | 
				
			||||||
use App\Exception\NoValidChoiceException;
 | 
					 | 
				
			||||||
use App\DBAL\Types\Meta\Right\CRUDType;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * @todo Remove relation attribut!
 | 
					 * @todo Remove relation attribut!
 | 
				
			||||||
@@ -98,17 +95,4 @@ class Right extends AbstractMeta implements RightInterface
 | 
				
			|||||||
        $this->grant = true;
 | 
					        $this->grant = true;
 | 
				
			||||||
        $this->priority = 0;
 | 
					        $this->priority = 0;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * {@inheritdoc}
 | 
					 | 
				
			||||||
     *
 | 
					 | 
				
			||||||
     * @see \App\Entity\Attribut\LayerAttributInterface::setLayer()
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    public function setLayer(string $layer): void
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        if (!array_key_exists($layer, LayerType::getChoices())) {
 | 
					 | 
				
			||||||
            throw new NoValidChoiceException();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        $this->layer = $layer;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,17 +6,21 @@ use PHPUnit\Framework\TestCase;
 | 
				
			|||||||
use App\Entity\Attribut\LayerAttributInterface;
 | 
					use App\Entity\Attribut\LayerAttributInterface;
 | 
				
			||||||
use App\Entity\Attribut\LayerAttribut;
 | 
					use App\Entity\Attribut\LayerAttribut;
 | 
				
			||||||
use App\DBAL\Types\Meta\Right\LayerType;
 | 
					use App\DBAL\Types\Meta\Right\LayerType;
 | 
				
			||||||
 | 
					use App\Exception\NoValidChoiceException;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * @author kevinfrantz
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
class LayerAttributTest extends TestCase
 | 
					class LayerAttributTest extends TestCase
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * @var LayerAttributInterface
 | 
					     * @var LayerAttributInterface
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    protected $layer;
 | 
					    protected $layerAttribut;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function setUp(): void
 | 
					    public function setUp(): void
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->layer = new class() implements LayerAttributInterface {
 | 
					        $this->layerAttribut = new class() implements LayerAttributInterface {
 | 
				
			||||||
            use LayerAttribut;
 | 
					            use LayerAttribut;
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -24,14 +28,16 @@ class LayerAttributTest extends TestCase
 | 
				
			|||||||
    public function testConstruct(): void
 | 
					    public function testConstruct(): void
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->expectException(\TypeError::class);
 | 
					        $this->expectException(\TypeError::class);
 | 
				
			||||||
        $this->layer->getLayer();
 | 
					        $this->layerAttribut->getLayer();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function testAccessors(): void
 | 
					    public function testAccessors(): void
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        foreach (LayerType::getChoices() as $value) {
 | 
					        foreach (LayerType::getChoices() as $enum) {
 | 
				
			||||||
            $this->assertNull($this->layer->setLayer($value));
 | 
					            $this->assertNull($this->layerAttribut->setLayer($enum));
 | 
				
			||||||
            $this->assertEquals($value, $this->layer->getLayer());
 | 
					            $this->assertEquals($enum, $this->layerAttribut->getLayer());
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        $this->expectException(NoValidChoiceException::class);
 | 
				
			||||||
 | 
					        $this->layerAttribut->setLayer('NoneValidLayer');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -83,9 +83,9 @@ class RightTest extends TestCase
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public function testLayer(): void
 | 
					    public function testLayer(): void
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        foreach (LayerType::getChoices() as $key => $value) {
 | 
					        foreach (LayerType::getChoices() as $choice) {
 | 
				
			||||||
            $this->assertNull($this->right->setLayer($key));
 | 
					            $this->assertNull($this->right->setLayer($choice));
 | 
				
			||||||
            $this->assertEquals($key, $this->right->getLayer());
 | 
					            $this->assertEquals($choice, $this->right->getLayer());
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        $this->expectException(NoValidChoiceException::class);
 | 
					        $this->expectException(NoValidChoiceException::class);
 | 
				
			||||||
        $this->right->setLayer('NoneValidLayer');
 | 
					        $this->right->setLayer('NoneValidLayer');
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user