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.

TopicModel::createTopic()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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\Topic;
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 TopicModel extends BaseModel implements ModelInterface
33
{
34
    /**
35
     *
36
     * @access public
37
     * @return \CCDNForum\ForumBundle\Entity\Topic
38
     */
39
    public function createTopic()
40
    {
41
        return $this->getManager()->createTopic();
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 createTopic() does only exist in the following implementations of said interface: CCDNForum\ForumBundle\Mo...nt\Manager\TopicManager.

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...
42
    }
43
44
    /**
45
     *
46
     * @access public
47
     * @param  int                                                      $boardId
48
     * @param  int                                                      $page
49
     * @param  int                                                      $itemsPerPage
50
     * @param  bool                                                     $canViewDeletedTopics
51
     * @return \Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination
52
     */
53
    public function findAllTopicsPaginatedByBoardId($boardId, $page, $itemsPerPage = 25, $canViewDeletedTopics = false)
54
    {
55
        return $this->getRepository()->findAllTopicsPaginatedByBoardId($boardId, $page, $itemsPerPage, $canViewDeletedTopics);
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 findAllTopicsPaginatedByBoardId() does only exist in the following implementations of said interface: CCDNForum\ForumBundle\Mo...ository\TopicRepository.

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...
56
    }
57
58
    /**
59
     *
60
     * @access public
61
     * @param  int                                                      $boardId
62
     * @param  bool                                                     $canViewDeletedTopics
63
     * @return \Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination
64
     */
65
    public function findAllTopicsStickiedByBoardId($boardId, $canViewDeletedTopics = false)
66
    {
67
        return $this->getRepository()->findAllTopicsStickiedByBoardId($boardId, $canViewDeletedTopics);
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 findAllTopicsStickiedByBoardId() does only exist in the following implementations of said interface: CCDNForum\ForumBundle\Mo...ository\TopicRepository.

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...
68
    }
69
70
    /**
71
     *
72
     * @access public
73
     * @param  int                                 $topicId
74
     * @param  bool                                $canViewDeletedTopics
75
     * @return \CCDNForum\ForumBundle\Entity\Topic
76
     */
77
    public function findOneTopicByIdWithBoardAndCategory($topicId, $canViewDeletedTopics = false)
78
    {
79
        return $this->getRepository()->findOneTopicByIdWithBoardAndCategory($topicId, $canViewDeletedTopics);
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 findOneTopicByIdWithBoardAndCategory() does only exist in the following implementations of said interface: CCDNForum\ForumBundle\Mo...ository\TopicRepository.

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...
80
    }
81
82
    /**
83
     *
84
     * @access public
85
     * @param  int                                 $topicId
86
     * @param  bool                                $canViewDeletedTopics
87
     * @return \CCDNForum\ForumBundle\Entity\Topic
88
     */
89
    public function findOneTopicByIdWithPosts($topicId, $canViewDeletedTopics = false)
90
    {
91
        return $this->getRepository()->findOneTopicByIdWithPosts($topicId, $canViewDeletedTopics);
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 findOneTopicByIdWithPosts() does only exist in the following implementations of said interface: CCDNForum\ForumBundle\Mo...ository\TopicRepository.

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...
92
    }
93
94
    /**
95
     *
96
     * @access public
97
     * @param  int                                 $topicId
0 ignored issues
show
Bug introduced by
There is no parameter named $topicId. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

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

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

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

Loading history...
98
     * @return \CCDNForum\ForumBundle\Entity\Topic
99
     */
100
    public function findLastTopicForBoardByIdWithLastPost($boardId)
101
    {
102
        return $this->getRepository()->findLastTopicForBoardByIdWithLastPost($boardId);
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 findLastTopicForBoardByIdWithLastPost() does only exist in the following implementations of said interface: CCDNForum\ForumBundle\Mo...ository\TopicRepository.

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...
103
    }
104
105
    /**
106
     *
107
     * @access public
108
     * @param  int   $boardId
109
     * @return Array
110
     */
111
    public function getTopicAndPostCountForBoardById($boardId)
112
    {
113
        return $this->getRepository()->getTopicAndPostCountForBoardById($boardId);
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 getTopicAndPostCountForBoardById() does only exist in the following implementations of said interface: CCDNForum\ForumBundle\Mo...ository\TopicRepository.

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...
114
    }
115
116
    /**
117
     *
118
     * Post must have a set topic for topic to be set correctly.
119
     *
120
     * @access public
121
     * @param  \CCDNForum\ForumBundle\Entity\Post                              $post
0 ignored issues
show
Bug introduced by
There is no parameter named $post. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

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

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

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

Loading history...
122
     * @return \CCDNForum\ForumBundle\Model\Component\Manager\ManagerInterface
123
     */
124
    public function saveTopic(Topic $topic)
125
    {
126
        return $this->getManager()->saveTopic($topic);
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 saveTopic() does only exist in the following implementations of said interface: CCDNForum\ForumBundle\Mo...nt\Manager\TopicManager.

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...
127
    }
128
129
    /**
130
     *
131
     * @access public
132
     * @param  \CCDNForum\ForumBundle\Entity\Topic                             $topic
133
     * @return \CCDNForum\ForumBundle\Model\Component\Manager\ManagerInterface
134
     */
135
    public function updateTopic(Topic $topic)
136
    {
137
        return $this->getManager()->updateTopic($topic);
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 updateTopic() does only exist in the following implementations of said interface: CCDNForum\ForumBundle\Mo...nt\Manager\TopicManager.

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...
138
    }
139
140
    /**
141
     *
142
     * @access public
143
     * @param  \CCDNForum\ForumBundle\Entity\Topic                             $topic
144
     * @return \CCDNForum\ForumBundle\Model\Component\Manager\ManagerInterface
145
     */
146
    public function incrementViewCounter(Topic $topic)
147
    {
148
        return $this->getManager()->incrementViewCounter($topic);
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 incrementViewCounter() does only exist in the following implementations of said interface: CCDNForum\ForumBundle\Mo...nt\Manager\TopicManager.

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...
149
    }
150
151
    /**
152
     *
153
     * @access public
154
     * @param  \CCDNForum\ForumBundle\Entity\Topic                             $topic
155
     * @return \CCDNForum\ForumBundle\Model\Component\Manager\ManagerInterface
156
     */
157
    public function restore(Topic $topic)
158
    {
159
        return $this->getManager()->restore($topic);
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 restore() does only exist in the following implementations of said interface: CCDNForum\ForumBundle\Mo...ent\Manager\PostManager, CCDNForum\ForumBundle\Mo...nt\Manager\TopicManager.

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...
160
    }
161
162
    /**
163
     *
164
     * @access public
165
     * @param  \CCDNForum\ForumBundle\Entity\Topic                             $topic
166
     * @param  \Symfony\Component\Security\Core\User\UserInterface             $user
167
     * @return \CCDNForum\ForumBundle\Model\Component\Manager\ManagerInterface
168
     */
169
    public function softDelete(Topic $topic, UserInterface $user)
170
    {
171
        return $this->getManager()->softDelete($topic, $user);
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 softDelete() does only exist in the following implementations of said interface: CCDNForum\ForumBundle\Mo...ent\Manager\PostManager, CCDNForum\ForumBundle\Mo...nt\Manager\TopicManager.

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...
172
    }
173
174
    /**
175
     *
176
     * @access public
177
     * @param  \CCDNForum\ForumBundle\Entity\Topic                             $topic
178
     * @param  \Symfony\Component\Security\Core\User\UserInterface             $user
179
     * @return \CCDNForum\ForumBundle\Model\Component\Manager\ManagerInterface
180
     */
181
    public function sticky(Topic $topic, UserInterface $user)
182
    {
183
        return $this->getManager()->sticky($topic, $user);
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 sticky() does only exist in the following implementations of said interface: CCDNForum\ForumBundle\Mo...nt\Manager\TopicManager.

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...
184
    }
185
186
    /**
187
     *
188
     * @access public
189
     * @param  \CCDNForum\ForumBundle\Entity\Topic                             $topic
190
     * @return \CCDNForum\ForumBundle\Model\Component\Manager\ManagerInterface
191
     */
192
    public function unsticky(Topic $topic)
193
    {
194
        return $this->getManager()->unsticky($topic);
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 unsticky() does only exist in the following implementations of said interface: CCDNForum\ForumBundle\Mo...nt\Manager\TopicManager.

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...
195
    }
196
197
    /**
198
     *
199
     * @access public
200
     * @param  \CCDNForum\ForumBundle\Entity\Topic                             $topic
201
     * @param  \Symfony\Component\Security\Core\User\UserInterface             $user
202
     * @return \CCDNForum\ForumBundle\Model\Component\Manager\ManagerInterface
203
     */
204
    public function close(Topic $topic, UserInterface $user)
205
    {
206
        return $this->getManager()->close($topic, $user);
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 close() does only exist in the following implementations of said interface: CCDNForum\ForumBundle\Mo...nt\Manager\TopicManager.

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...
207
    }
208
209
    /**
210
     *
211
     * @access public
212
     * @param  \CCDNForum\ForumBundle\Entity\Topic                             $topic
213
     * @return \CCDNForum\ForumBundle\Model\Component\Manager\ManagerInterface
214
     */
215
    public function reopen(Topic $topic)
216
    {
217
        return $this->getManager()->reopen($topic);
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 reopen() does only exist in the following implementations of said interface: CCDNForum\ForumBundle\Mo...nt\Manager\TopicManager.

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...
218
    }
219
}
220