These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Kunstmaan\VotingBundle\Helper; |
||
4 | |||
5 | use Doctrine\ORM\EntityManagerInterface; |
||
6 | |||
7 | /** |
||
8 | * Abstract Helper class for Voting |
||
9 | */ |
||
10 | abstract class AbstractVotingHelper |
||
11 | { |
||
12 | /** |
||
13 | * @var EntityManagerInterface |
||
14 | */ |
||
15 | protected $em; |
||
16 | |||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $repository; |
||
21 | |||
22 | public function __construct(EntityManagerInterface $em) |
||
23 | { |
||
24 | $this->em = $em; |
||
25 | } |
||
26 | |||
27 | /** |
||
28 | * @param string $reference Reference to filter the votes by |
||
29 | * |
||
30 | * @return array Returns an array of votes |
||
31 | */ |
||
32 | public function byReference($reference) |
||
33 | { |
||
34 | return $this->em->getRepository($this->repository) |
||
0 ignored issues
–
show
|
|||
35 | ->findByReference($reference); |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * @param string $reference The reference to filter the votes by |
||
40 | * |
||
41 | * @return mixed Returns the count |
||
42 | */ |
||
43 | public function countByReference($reference) |
||
44 | { |
||
45 | return $this->em->getRepository($this->repository) |
||
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Doctrine\Persistence\ObjectRepository as the method countByReference() does only exist in the following implementations of said interface: Kunstmaan\VotingBundle\R...\AbstractVoteRepository , Kunstmaan\VotingBundle\R...\FacebookLikeRepository , Kunstmaan\VotingBundle\R...\FacebookSendRepository , Kunstmaan\VotingBundle\R...LinkedInShareRepository , Kunstmaan\VotingBundle\R...Down\DownVoteRepository , Kunstmaan\VotingBundle\R...UpDown\UpVoteRepository .
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
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
Loading history...
|
|||
46 | ->countByReference($reference); |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * @param string $reference The reference to filter the votes by |
||
51 | * |
||
52 | * @return mixed Returns the sum of the values |
||
53 | */ |
||
54 | public function getValueByReference($reference) |
||
55 | { |
||
56 | return $this->em->getRepository($this->repository) |
||
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Doctrine\Persistence\ObjectRepository as the method getValueByReference() does only exist in the following implementations of said interface: Kunstmaan\VotingBundle\R...\AbstractVoteRepository , Kunstmaan\VotingBundle\R...\FacebookLikeRepository , Kunstmaan\VotingBundle\R...\FacebookSendRepository , Kunstmaan\VotingBundle\R...LinkedInShareRepository , Kunstmaan\VotingBundle\R...Down\DownVoteRepository , Kunstmaan\VotingBundle\R...UpDown\UpVoteRepository .
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
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
Loading history...
|
|||
57 | ->getValueByReference($reference); |
||
58 | } |
||
59 | } |
||
60 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.