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.

RegistryModel   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A findOrCreateOneRegistryForUser() 0 12 2
A findOneRegistryForUserById() 0 4 1
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\FrontModel;
15
16
use Symfony\Component\Security\Core\User\UserInterface;
17
use CCDNForum\ForumBundle\Model\FrontModel\BaseModel;
18
use CCDNForum\ForumBundle\Model\FrontModel\ModelInterface;
19
use CCDNForum\ForumBundle\Entity\Registry;
20
21
/**
22
 *
23
 * @category CCDNForum
24
 * @package  ForumBundle
25
 *
26
 * @author   Reece Fowell <[email protected]>
27
 * @license  http://opensource.org/licenses/MIT MIT
28
 * @version  Release: 2.0
29
 * @link     https://github.com/codeconsortium/CCDNForumForumBundle
30
 *
31
 */
32
class RegistryModel extends BaseModel implements ModelInterface
33
{
34
    /**
35
     *
36
     * @access public
37
     * @param  \Symfony\Component\Security\Core\User\UserInterface $user
38
     * @return \CCDNForum\ForumBundle\Entity\Registry
39
     */
40
    public function findOrCreateOneRegistryForUser(UserInterface $user)
41
    {
42
        $registry = $this->findOneRegistryForUserById($user->getId());
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Symfony\Component\Security\Core\User\UserInterface as the method getId() does only exist in the following implementations of said interface: CCDNForum\ForumBundle\Te...ctional\src\Entity\User.

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...
43
44
        if (! $registry) {
45
            $registry = $this->createRegistry();
46
            $registry->setOwnedBy($user);
47
            $this->saveRegistry($registry);
48
        }
49
50
        return $registry;
51
    }
52
53
    /**
54
     *
55
     * @access public
56
     * @param  int                                    $userId
57
     * @return \CCDNForum\ForumBundle\Entity\Registry
58
     */
59
    public function findOneRegistryForUserById($userId)
60
    {
61
        return $this->getRepository()->findOneRegistryForUserById($userId);
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface CCDNForum\ForumBundle\Mo...ory\RepositoryInterface as the method findOneRegistryForUserById() does only exist in the following implementations of said interface: CCDNForum\ForumBundle\Mo...tory\RegistryRepository.

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...
62
    }
63
64
    /**
65
     *
66
     * @access public
67
     * @return \CCDNForum\ForumBundle\Entity\Registry
68
     */
69
    public function createRegistry()
70
    {
71
        return $this->getManager()->createRegistry();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface CCDNForum\ForumBundle\Mo...anager\ManagerInterface as the method createRegistry() does only exist in the following implementations of said interface: CCDNForum\ForumBundle\Mo...Manager\RegistryManager.

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...
72
    }
73
74
    /**
75
     *
76
     * @access public
77
     * @param  \CCDNForum\ForumBundle\Entity\Registry                $registryModel
0 ignored issues
show
Documentation introduced by
There is no parameter named $registryModel. Did you maybe mean $registry?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
78
     * @return \CCDNForum\ForumBundle\Model\FrontModel\RegistryModel
79
     */
80
    public function saveRegistry(Registry $registry)
81
    {
82
        $this->getManager()->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...anager\ManagerInterface as the method saveRegistry() does only exist in the following implementations of said interface: CCDNForum\ForumBundle\Mo...Manager\RegistryManager.

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...
83
84
        return $this;
85
    }
86
}
87