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

RecyclingMissionManager::save()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 27
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 14
nc 2
nop 0
dl 0
loc 27
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * RecyclingMissionManager
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
use Asylamba\Classes\Scheduler\RealTimeActionScheduler;
16
17
use Asylamba\Modules\Athena\Model\RecyclingMission;
18
19
class RecyclingMissionManager
20
{
21
	/** @var EntityManager **/
22
	protected $entityManager;
23
	/** @var RealTimeActionScheduler **/
24
	protected $realtimeActionScheduler;
25
26
	/**
27
	 * @param EntityManager $entityManager
28
	 * @param RealTimeActionScheduler $realtimeActionScheduler
29
	 */
30
	public function __construct(EntityManager $entityManager, RealTimeActionScheduler $realtimeActionScheduler)
31
	{
32
		$this->entityManager = $entityManager;
33
		$this->realtimeActionScheduler = $realtimeActionScheduler;
34
	}
35
	
36
	public function scheduleMissions()
37
	{
38
		$missions = $this->entityManager->getRepository(RecyclingMission::class)->getAll();
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 getAll() does only exist in the following sub-classes of Asylamba\Classes\Entity\AbstractRepository: Asylamba\Modules\Athena\...BuildingQueueRepository, Asylamba\Modules\Athena\...rcialShippingRepository, Asylamba\Modules\Athena\...y\OrbitalBaseRepository, Asylamba\Modules\Athena\...yclingMissionRepository, Asylamba\Modules\Athena\...ory\ShipQueueRepository, Asylamba\Modules\Demeter...ository\ColorRepository, Asylamba\Modules\Gaia\Repository\SectorRepository, Asylamba\Modules\Gaia\Repository\SystemRepository, Asylamba\Modules\Prometh...chnologyQueueRepository. 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...
39
		
40
		foreach ($missions as $mission) {
41
			$this->realtimeActionScheduler->schedule(
42
				'athena.orbital_base_manager',
43
				'uRecycling',
44
				$mission,
45
				$mission->uRecycling
46
			);
47
		}
48
	}
49
	
50
	/**
51
	 * @param int $id
52
	 * @return RecyclingMission
53
	 */
54
	public function get($id)
55
	{
56
		return $this->entityManager->getRepository(RecyclingMission::class)->get($id);
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 get() does only exist in the following sub-classes of Asylamba\Classes\Entity\AbstractRepository: Asylamba\Modules\Ares\Re...ory\CommanderRepository, Asylamba\Modules\Ares\Re...ry\LiveReportRepository, Asylamba\Modules\Ares\Repository\ReportRepository, Asylamba\Modules\Athena\...BuildingQueueRepository, Asylamba\Modules\Athena\...mmercialRouteRepository, Asylamba\Modules\Athena\...rcialShippingRepository, Asylamba\Modules\Athena\...y\OrbitalBaseRepository, Asylamba\Modules\Athena\...yclingMissionRepository, Asylamba\Modules\Athena\...ory\ShipQueueRepository, Asylamba\Modules\Athena\...y\TransactionRepository, Asylamba\Modules\Demeter...ository\ColorRepository, Asylamba\Modules\Demeter...ion\CandidateRepository, Asylamba\Modules\Demeter...tion\ElectionRepository, Asylamba\Modules\Demeter...m\FactionNewsRepository, Asylamba\Modules\Demeter...itory\Law\LawRepository, Asylamba\Modules\Gaia\Repository\PlaceRepository, Asylamba\Modules\Gaia\Repository\SectorRepository, Asylamba\Modules\Gaia\Repository\SystemRepository, Asylamba\Modules\Hermes\...\NotificationRepository, Asylamba\Modules\Prometh...chnologyQueueRepository, Asylamba\Modules\Zeus\Repository\PlayerRepository. 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...
57
	}
58
	
59
	/**
60
	 * @param int $baseId
61
	 * @return array
62
	 */
63
	public function getBaseMissions($baseId)
64
	{
65
		return $this->entityManager->getRepository(RecyclingMission::class)->getBaseMissions($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 getBaseMissions() does only exist in the following sub-classes of Asylamba\Classes\Entity\AbstractRepository: Asylamba\Modules\Athena\...yclingMissionRepository. 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...
66
	}
67
	
68
	/**
69
	 * @param int $baseId
70
	 * @return array
71
	 */
72
	public function getBaseActiveMissions($baseId)
73
	{
74
		return $this->entityManager->getRepository(RecyclingMission::class)->getBaseActiveMissions($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 getBaseActiveMissions() does only exist in the following sub-classes of Asylamba\Classes\Entity\AbstractRepository: Asylamba\Modules\Athena\...yclingMissionRepository. 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...
75
	}
76
77
	/**
78
	 * @param RecyclingMission $recyclingMission
79
	 */
80
	public function add(RecyclingMission $recyclingMission)
81
	{
82
		$this->entityManager->persist($recyclingMission);
83
		$this->entityManager->flush($recyclingMission);
84
		
85
		$this->realtimeActionScheduler->schedule(
86
			'athena.orbital_base_manager',
87
			'uRecycling',
88
			$recyclingMission,
0 ignored issues
show
Documentation introduced by
$recyclingMission is of type object<Asylamba\Modules\...Model\RecyclingMission>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
89
			$recyclingMission->uRecycling
90
		);
91
	}
92
	
93
	/**
94
	 * @param int $baseId
95
	 */
96
	public function removeBaseMissions($baseId)
97
	{
98
		foreach ($this->getBaseActiveMissions($baseId) as $mission) {
99
			$this->realtimeActionScheduler->cancel($mission, $mission->uRecycling);
100
		}
101
		$this->entityManager->getRepository(RecyclingMission::class)->removeBaseMissions($baseId);
0 ignored issues
show
Bug introduced by
The method removeBaseMissions() does not exist on Asylamba\Classes\Entity\AbstractRepository. Did you maybe mean remove()?

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.

Loading history...
102
	}
103
}