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.
Completed
Push — master ( 856a6b...b18c19 )
by Jacky
05:00
created

RecyclingLogManager::fill()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 21
nc 2
nop 1
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * RecyclingLogManager
5
 *
6
 * @author Jacky Casas
7
 * @copyright Asylamba
8
 *
9
 * @package Zeus
10
 * @version 09.02.15
11
 **/
12
namespace Asylamba\Modules\Athena\Manager;
13
14
use Asylamba\Classes\Entity\EntityManager;
15
16
use Asylamba\Modules\Athena\Model\RecyclingLog;
17
18
class RecyclingLogManager {
19
	/** @var EntityManager **/
20
	protected $entityManager;
21
22
	/**
23
	 * @param EntityManager $entityManager
24
	 */
25
	public function __construct(EntityManager $entityManager) {
26
		$this->entityManager = $entityManager;
27
	}
28
29
	/**
30
	 * @param RecyclingLog $recyclingLog
31
	 */
32
	public function add(RecyclingLog $recyclingLog)
33
	{
34
		$this->entityManager->persist($recyclingLog);
35
		$this->entityManager->flush($recyclingLog);
36
	}
37
	
38
	/**
39
	 * @param int $baseId
40
	 * @return array
41
	 */
42
	public function getBaseActiveMissionsLogs($baseId)
43
	{
44
		return $this->entityManager->getRepository(RecyclingLog::class)->getBaseActiveMissionsLogs($baseId);
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Asylamba\Classes\Entity\AbstractRepository as the method getBaseActiveMissionsLogs() does only exist in the following sub-classes of Asylamba\Classes\Entity\AbstractRepository: Asylamba\Modules\Athena\...\RecyclingLogRepository. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends 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 sub-classes 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 parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
45
	}
46
}