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.

SubscriptionManager::markAsUnread()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 8
rs 9.4285
cc 1
eloc 4
nc 1
nop 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 Symfony\Component\Security\Core\User\UserInterface;
17
18
use CCDNForum\ForumBundle\Model\Component\Manager\ManagerInterface;
19
use CCDNForum\ForumBundle\Model\Component\Manager\BaseManager;
20
21
use CCDNForum\ForumBundle\Entity\Subscription;
22
use CCDNForum\ForumBundle\Entity\Topic;
23
24
/**
25
 *
26
 * @category CCDNForum
27
 * @package  ForumBundle
28
 *
29
 * @author   Reece Fowell <[email protected]>
30
 * @license  http://opensource.org/licenses/MIT MIT
31
 * @version  Release: 2.0
32
 * @link     https://github.com/codeconsortium/CCDNForumForumBundle
33
 *
34
 */
35
class SubscriptionManager extends BaseManager implements ManagerInterface
36
{
37
    /**
38
     *
39
     * @access public
40
     * @return \CCDNForum\ForumBundle\Entity\Subscription
41
     */
42
    public function createSubscription()
43
    {
44
        return $this->gateway->createSubscription();
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 createSubscription() does only exist in the following implementations of said interface: CCDNForum\ForumBundle\Mo...way\SubscriptionGateway.

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...
45
    }
46
47
    /**
48
     *
49
     * @access public
50
     * @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...
51
     * @param  \Symfony\Component\Security\Core\User\UserInterface $userId
0 ignored issues
show
Bug introduced by
There is no parameter named $userId. 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...
52
     * @return \CCDNForum\ForumBundle\Manager\ManagerInterface
0 ignored issues
show
Documentation introduced by
Should the return type not be SubscriptionManager?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
53
     */
54
    public function subscribe(Topic $topic, UserInterface $user)
55
    {
56
        $subscription = $this->model->findOneSubscriptionForTopicByIdAndUserById($topic->getId(), $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...
Bug introduced by
It seems like you code against a concrete implementation and not the interface CCDNForum\ForumBundle\Mo...ontModel\ModelInterface as the method findOneSubscriptionForTopicByIdAndUserById() does only exist in the following implementations of said interface: CCDNForum\ForumBundle\Mo...Model\SubscriptionModel.

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...
57
58
        if (! $subscription) {
59
            $subscription = new Subscription();
60
        }
61
62
        if (! $subscription->isSubscribed()) {
63
            $subscription->setSubscribed(true);
64
            $subscription->setOwnedBy($user);
65
            $subscription->setTopic($topic);
66
            $subscription->setRead(true);
67
            $subscription->setForum($topic->getBoard()->getCategory()->getForum());
68
69
            $this->gateway->saveSubscription($subscription);
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 saveSubscription() does only exist in the following implementations of said interface: CCDNForum\ForumBundle\Mo...way\SubscriptionGateway.

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...
70
        }
71
72
        return $this;
73
    }
74
75
    /**
76
     *
77
     * @access public
78
     * @param  \CCDNForum\ForumBundle\Entity\Topic             $topic
79
     * @param  int                                             $userId
80
     * @return \CCDNForum\ForumBundle\Manager\ManagerInterface
0 ignored issues
show
Documentation introduced by
Should the return type not be SubscriptionManager?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
81
     */
82
    public function unsubscribe(Topic $topic, $userId)
83
    {
84
        $subscription = $this->model->findOneSubscriptionForTopicByIdAndUserById($topic->getId(), $userId);
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface CCDNForum\ForumBundle\Mo...ontModel\ModelInterface as the method findOneSubscriptionForTopicByIdAndUserById() does only exist in the following implementations of said interface: CCDNForum\ForumBundle\Mo...Model\SubscriptionModel.

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...
85
86
        if (! $subscription) {
87
            return $this;
88
        }
89
90
        $subscription->setSubscribed(false);
91
        $subscription->setRead(true);
92
93
        $this->gateway->saveSubscription($subscription);
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 saveSubscription() does only exist in the following implementations of said interface: CCDNForum\ForumBundle\Mo...way\SubscriptionGateway.

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...
94
95
        return $this;
96
    }
97
98
    /**
99
     *
100
     * @access public
101
     * @param  \CCDNForum\ForumBundle\Entity\Subscription      $subscription
102
     * @return \CCDNForum\ForumBundle\Manager\ManagerInterface
0 ignored issues
show
Documentation introduced by
Should the return type not be SubscriptionManager?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
103
     */
104
    public function markAsRead(Subscription $subscription)
105
    {
106
        $subscription->setRead(true);
107
108
        $this->persist($subscription)->flush();
109
110
        return $this;
111
    }
112
113
    /**
114
     *
115
     * @access public
116
     * @param  \CCDNForum\ForumBundle\Entity\Subscription      $subscription
117
     * @return \CCDNForum\ForumBundle\Manager\ManagerInterface
0 ignored issues
show
Documentation introduced by
Should the return type not be SubscriptionManager?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
118
     */
119
    public function markAsUnread(Subscription $subscription)
120
    {
121
        $subscription->setRead(false);
122
123
        $this->persist($subscription)->flush();
124
125
        return $this;
126
    }
127
128
    /**
129
     *
130
     * @access public
131
     * @param  \Doctrine\Common\Collections\ArrayCollection        $subscriptions
132
     * @param  \Symfony\Component\Security\Core\User\UserInterface $exceptUser
133
     * @return \CCDNForum\ForumBundle\Manager\ManagerInterface
0 ignored issues
show
Documentation introduced by
Should the return type not be \CCDNForum\ForumBundle\M...r\ManagerInterface|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
134
     */
135
    public function markTheseAsUnread($subscriptions, UserInterface $exceptUser)
136
    {
137
        foreach ($subscriptions as $subscription) {
138
            if ($subscription->getOwnedBy()) {
139
                if ($subscription->getOwnedBy()->getId() != $exceptUser->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...
140
                    $subscription->setRead(false);
141
142
                    $this->persist($subscription);
143
                }
144
            }
145
        }
146
147
        $this->flush();
148
    }
149
}
150