Completed
Push — master ( 8e9b2d...71f485 )
by Quentin
17:01 queued 12:32
created

ZoneDomain::removeComponent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 7
cp 0
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Synapse\Cmf\Framework\Theme\Zone\Domain;
4
5
use Majora\Framework\Domain\ActionDispatcherDomain;
6
use Majora\Framework\Domain\Action\ActionFactory;
7
use Synapse\Cmf\Framework\Theme\ComponentType\Model\ComponentTypeInterface;
8
use Synapse\Cmf\Framework\Theme\Component\Entity\ComponentCollection;
9
use Synapse\Cmf\Framework\Theme\Component\Model\ComponentInterface;
10
use Synapse\Cmf\Framework\Theme\ZoneType\Model\ZoneTypeInterface;
11
use Synapse\Cmf\Framework\Theme\Zone\Model\ZoneInterface;
12
13
/**
14
 * Zone domain use cases class.
15
 */
16
class ZoneDomain extends ActionDispatcherDomain implements DomainInterface
17
{
18
    /**
19
     * @var ActionFactory
20
     */
21
    protected $commandFactory;
22
23
    /**
24
     * Construct.
25
     *
26
     * @param ActionFactory $commandFactory
27
     */
28 6
    public function __construct(ActionFactory $commandFactory)
29
    {
30 6
        $this->commandFactory = $commandFactory;
31
32 6
        parent::__construct($commandFactory); // backward compatibility
33 6
    }
34
35
    /**
36
     * @see DomainInterface::create()
37
     */
38 2
    public function create(ZoneTypeInterface $zoneType, ComponentCollection $components = null)
39
    {
40 2
        return $this->commandFactory
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Majora\Framework\Domain\Action\ActionInterface as the method setZoneType() does only exist in the following implementations of said interface: Synapse\Cmf\Framework\Th...n\Command\CreateCommand.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
41 2
            ->createAction('create')
42 2
                ->setZoneType($zoneType)
43 2
                ->setComponents($components ?: new ComponentCollection())
44 2
            ->resolve()
45 1
        ;
46
    }
47
48
    /**
49
     * @see DomainInterface::edit()
50
     */
51 2
    public function edit(ZoneInterface $zone, ComponentCollection $components)
52
    {
53 2
        return $this->commandFactory
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Majora\Framework\Domain\Action\ActionInterface as the method init() does only exist in the following implementations of said interface: Majora\Framework\Domain\Action\AbstractAction, Synapse\Cmf\Framework\Me...e\Action\AbstractAction, Synapse\Cmf\Framework\Me...n\Dal\AbstractDalAction, Synapse\Cmf\Framework\Me...Action\Dal\CreateAction, Synapse\Cmf\Framework\Me...Action\Dal\UploadAction, Synapse\Cmf\Framework\Me...e\Action\AbstractAction, Synapse\Cmf\Framework\Me...n\Dal\AbstractDalAction, Synapse\Cmf\Framework\Me...Action\Dal\CreateAction, Synapse\Cmf\Framework\Me...Action\Dal\DeleteAction, Synapse\Cmf\Framework\Me...Action\Dal\UpdateAction, Synapse\Cmf\Framework\Me...e\Action\AbstractAction, Synapse\Cmf\Framework\Me...n\Dal\AbstractDalAction, Synapse\Cmf\Framework\Me...Action\Dal\CreateAction, Synapse\Cmf\Framework\Me...Action\Dal\DeleteAction, Synapse\Cmf\Framework\Me...Action\Dal\FormatAction, Synapse\Cmf\Framework\Me...Action\Dal\UpdateAction, Synapse\Cmf\Framework\Me...Action\Dal\UploadAction, Synapse\Cmf\Framework\Th...n\Command\DeleteCommand, Synapse\Cmf\Framework\Th...n\Command\UpdateCommand, Synapse\Cmf\Framework\Th...n\Command\UpdateCommand, Synapse\Cmf\Framework\Th...and\AddComponentCommand, Synapse\Cmf\Framework\Th...\RemoveComponentCommand, Synapse\Cmf\Framework\Th...n\Command\UpdateCommand, Synapse\Page\Bundle\Action\Page\AbstractAction, Synapse\Page\Bundle\Action\Page\CreateAction, Synapse\Page\Bundle\Action\Page\DeleteAction, Synapse\Page\Bundle\Action\Page\UpdateAction.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
54 2
            ->createAction('edit')
55 2
                ->init($zone)
56 2
                ->setComponents($components)
57 2
            ->resolve()
58 1
        ;
59
    }
60
61
    /**
62
     * @see DomainInterface::addComponent()
63
     */
64 2
    public function addComponent(ZoneInterface $zone, ComponentTypeInterface $componentType, array $componentData = array())
65
    {
66 2
        return $this->commandFactory
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Majora\Framework\Domain\Action\ActionInterface as the method init() does only exist in the following implementations of said interface: Majora\Framework\Domain\Action\AbstractAction, Synapse\Cmf\Framework\Me...e\Action\AbstractAction, Synapse\Cmf\Framework\Me...n\Dal\AbstractDalAction, Synapse\Cmf\Framework\Me...Action\Dal\CreateAction, Synapse\Cmf\Framework\Me...Action\Dal\UploadAction, Synapse\Cmf\Framework\Me...e\Action\AbstractAction, Synapse\Cmf\Framework\Me...n\Dal\AbstractDalAction, Synapse\Cmf\Framework\Me...Action\Dal\CreateAction, Synapse\Cmf\Framework\Me...Action\Dal\DeleteAction, Synapse\Cmf\Framework\Me...Action\Dal\UpdateAction, Synapse\Cmf\Framework\Me...e\Action\AbstractAction, Synapse\Cmf\Framework\Me...n\Dal\AbstractDalAction, Synapse\Cmf\Framework\Me...Action\Dal\CreateAction, Synapse\Cmf\Framework\Me...Action\Dal\DeleteAction, Synapse\Cmf\Framework\Me...Action\Dal\FormatAction, Synapse\Cmf\Framework\Me...Action\Dal\UpdateAction, Synapse\Cmf\Framework\Me...Action\Dal\UploadAction, Synapse\Cmf\Framework\Th...n\Command\DeleteCommand, Synapse\Cmf\Framework\Th...n\Command\UpdateCommand, Synapse\Cmf\Framework\Th...n\Command\UpdateCommand, Synapse\Cmf\Framework\Th...and\AddComponentCommand, Synapse\Cmf\Framework\Th...\RemoveComponentCommand, Synapse\Cmf\Framework\Th...n\Command\UpdateCommand, Synapse\Page\Bundle\Action\Page\AbstractAction, Synapse\Page\Bundle\Action\Page\CreateAction, Synapse\Page\Bundle\Action\Page\DeleteAction, Synapse\Page\Bundle\Action\Page\UpdateAction.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
67 2
            ->createAction('add_component')
68 2
                ->init($zone)
69 2
                ->setComponentType($componentType)
70 2
                ->setComponentData($componentData)
71 2
            ->resolve()
72 1
        ;
73
    }
74
75
    /**
76
     * @see DomainInterface::removeComponent()
77
     */
78
    public function removeComponent(ZoneInterface $zone, ComponentInterface $component)
79
    {
80
        return $this->commandFactory
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Majora\Framework\Domain\Action\ActionInterface as the method init() does only exist in the following implementations of said interface: Majora\Framework\Domain\Action\AbstractAction, Synapse\Cmf\Framework\Me...e\Action\AbstractAction, Synapse\Cmf\Framework\Me...n\Dal\AbstractDalAction, Synapse\Cmf\Framework\Me...Action\Dal\CreateAction, Synapse\Cmf\Framework\Me...Action\Dal\UploadAction, Synapse\Cmf\Framework\Me...e\Action\AbstractAction, Synapse\Cmf\Framework\Me...n\Dal\AbstractDalAction, Synapse\Cmf\Framework\Me...Action\Dal\CreateAction, Synapse\Cmf\Framework\Me...Action\Dal\DeleteAction, Synapse\Cmf\Framework\Me...Action\Dal\UpdateAction, Synapse\Cmf\Framework\Me...e\Action\AbstractAction, Synapse\Cmf\Framework\Me...n\Dal\AbstractDalAction, Synapse\Cmf\Framework\Me...Action\Dal\CreateAction, Synapse\Cmf\Framework\Me...Action\Dal\DeleteAction, Synapse\Cmf\Framework\Me...Action\Dal\FormatAction, Synapse\Cmf\Framework\Me...Action\Dal\UpdateAction, Synapse\Cmf\Framework\Me...Action\Dal\UploadAction, Synapse\Cmf\Framework\Th...n\Command\DeleteCommand, Synapse\Cmf\Framework\Th...n\Command\UpdateCommand, Synapse\Cmf\Framework\Th...n\Command\UpdateCommand, Synapse\Cmf\Framework\Th...and\AddComponentCommand, Synapse\Cmf\Framework\Th...\RemoveComponentCommand, Synapse\Cmf\Framework\Th...n\Command\UpdateCommand, Synapse\Page\Bundle\Action\Page\AbstractAction, Synapse\Page\Bundle\Action\Page\CreateAction, Synapse\Page\Bundle\Action\Page\DeleteAction, Synapse\Page\Bundle\Action\Page\UpdateAction.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
81
            ->createAction('delete_component')
82
                ->init($zone)
83
                ->setComponent($component)
84
            ->resolve()
85
        ;
86
    }
87
}
88