GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

RegistryManager   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 25
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createRegistry() 0 4 1
A saveRegistry() 0 6 1
1
<?php
2
3
/*
4
 * This file is part of the CCDNForum ForumBundle
5
 *
6
 * (c) CCDN (c) CodeConsortium <http://www.codeconsortium.com/>
7
 *
8
 * Available on github <http://www.github.com/codeconsortium/>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace CCDNForum\ForumBundle\Model\Component\Manager;
15
16
use CCDNForum\ForumBundle\Model\Component\Manager\ManagerInterface;
17
use CCDNForum\ForumBundle\Model\Component\Manager\BaseManager;
18
use CCDNForum\ForumBundle\Entity\Registry;
19
20
/**
21
 *
22
 * @category CCDNForum
23
 * @package  ForumBundle
24
 *
25
 * @author   Reece Fowell <[email protected]>
26
 * @license  http://opensource.org/licenses/MIT MIT
27
 * @version  Release: 2.0
28
 * @link     https://github.com/codeconsortium/CCDNForumForumBundle
29
 *
30
 */
31
class RegistryManager extends BaseManager implements ManagerInterface
32
{
33
    /**
34
     *
35
     * @access public
36
     * @return \CCDNForum\ForumBundle\Entity\Registry
37
     */
38
    public function createRegistry()
39
    {
40
        return $this->gateway->createRegistry();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface CCDNForum\ForumBundle\Mo...ateway\GatewayInterface as the method createRegistry() does only exist in the following implementations of said interface: CCDNForum\ForumBundle\Mo...Gateway\RegistryGateway.

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
    }
42
43
    /**
44
     *
45
     * @access public
46
     * @param  \CCDNForum\ForumBundle\Entity\Registry                         $registry
47
     * @return \CCDNForum\ForumBundle\Model\Component\Manager\RegistryManager
48
     */
49
    public function saveRegistry(Registry $registry)
50
    {
51
        $this->gateway->saveRegistry($registry);
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface CCDNForum\ForumBundle\Mo...ateway\GatewayInterface as the method saveRegistry() does only exist in the following implementations of said interface: CCDNForum\ForumBundle\Mo...Gateway\RegistryGateway.

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...
52
53
        return $this;
54
    }
55
}
56