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 ( 710d07...9f3829 )
by Jacky
35s
created

PlaceManager   B

Complexity

Total Complexity 43

Size/Duplication

Total Lines 569
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 11

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 569
rs 8.3157
c 1
b 0
f 0
wmc 43
lcom 2
cbo 11

13 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A get() 0 7 2
A getByIds() 0 4 1
A getSystemPlaces() 0 4 1
A search() 0 3 1
A getPlayerPlaces() 0 4 1
A getNpcPlaces() 0 4 1
B updateNpcPlaces() 0 38 6
B updatePlayerPlaces() 0 27 5
A turnAsEmptyPlace() 0 4 1
A turnAsSpawnPlace() 0 6 1
D sendNotif() 0 302 15
C sendNotifForConquest() 0 101 7

How to fix   Complexity   

Complex Class

Complex classes like PlaceManager often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use PlaceManager, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/**
4
 * Place Manager
5
 *
6
 * @author Jacky Casas
7
 * @copyright Expansion - le jeu
8
 *
9
 * @package Gaia
10
 * @update 20.05.13
11
*/
12
namespace Asylamba\Modules\Gaia\Manager;
13
14
use Asylamba\Classes\Entity\EntityManager;
15
use Asylamba\Classes\Library\Utils;
16
use Asylamba\Classes\Library\Game;
17
use Asylamba\Classes\Library\Format;
18
19
use Asylamba\Modules\Hermes\Manager\NotificationManager;
20
21
use Asylamba\Modules\Gaia\Model\Place;
22
use Asylamba\Modules\Ares\Model\Commander;
23
use Asylamba\Modules\Ares\Model\Report;
24
use Asylamba\Modules\Hermes\Model\Notification;
25
use Asylamba\Modules\Gaia\Model\System;
26
27
use Asylamba\Modules\Gaia\Event\PlaceOwnerChangeEvent;
28
use Asylamba\Classes\Worker\EventDispatcher;
29
30
class PlaceManager {
31
	/** @var EntityManager **/
32
	protected $entityManager;
33
	/** @var NotificationManager **/
34
	protected $notificationManager;
35
	/** @var EventDispatcher **/
36
	protected $eventDispatcher;
37
	
38
	/**
39
	 * @param EntityManager $entityManager
40
	 * @param NotificationManager $notificationManager
41
	 * @param EventDispatcher $eventDispatcher
42
	 */
43
	public function __construct(EntityManager $entityManager, NotificationManager $notificationManager, EventDispatcher $eventDispatcher)
44
	{
45
		$this->entityManager = $entityManager;
46
		$this->notificationManager = $notificationManager;
47
		$this->eventDispatcher = $eventDispatcher;
48
	}
49
	
50
	/**
51
	 * @param int $id
52
	 * @return Place
53
	 */
54
	public function get($id)
55
	{
56
		if(($place = $this->entityManager->getRepository(Place::class)->get($id)) !== null) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after IF keyword; 0 found
Loading history...
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
			return $place;
58
		}
59
		return null;
60
	}
61
	
62
	/**
63
	 * @param int $ids
64
	 */
65
	public function getByIds($ids = [])
66
	{
67
		return $this->entityManager->getRepository(Place::class)->getByIds($ids);
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 getByIds() does only exist in the following sub-classes of Asylamba\Classes\Entity\AbstractRepository: Asylamba\Modules\Gaia\Repository\PlaceRepository. 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...
68
	}
69
	
70
	public function getSystemPlaces(System $system)
71
	{
72
		return $this->entityManager->getRepository(Place::class)->getSystemPlaces($system->getId());
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 getSystemPlaces() does only exist in the following sub-classes of Asylamba\Classes\Entity\AbstractRepository: Asylamba\Modules\Gaia\Repository\PlaceRepository. 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...
73
	}
74
75
	/**
76
	 * @param string $search
77
	 * @return array
78
	 */
79
	public function search($search) {
80
		return $this->entityManager->getRepository(Place::class)->search($search);
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 search() does only exist in the following sub-classes of Asylamba\Classes\Entity\AbstractRepository: Asylamba\Modules\Gaia\Repository\PlaceRepository, 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...
81
	}
82
	
83
	/**
84
	 * @return array
85
	 */
86
	public function getPlayerPlaces()
87
	{
88
		return $this->entityManager->getRepository(Place::class)->getPlayerPlaces();
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 getPlayerPlaces() does only exist in the following sub-classes of Asylamba\Classes\Entity\AbstractRepository: Asylamba\Modules\Gaia\Repository\PlaceRepository. 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...
89
	}
90
	
91
	/**
92
	 * @return array
93
	 */
94
	public function getNpcPlaces()
95
	{
96
		return $this->entityManager->getRepository(Place::class)->getNpcPlaces();
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 getNpcPlaces() does only exist in the following sub-classes of Asylamba\Classes\Entity\AbstractRepository: Asylamba\Modules\Gaia\Repository\PlaceRepository. 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...
97
	}
98
99
	public function updateNpcPlaces() {
100
		$places = $this->getNpcPlaces();
101
		$now   = Utils::now();
102
		$repository = $this->entityManager->getRepository(Place::class);
103
		$this->entityManager->beginTransaction();
104
		
105
		foreach ($places as $place) {
106
			if (Utils::interval($place->uPlace, $now, 's') === 0) {
107
				continue;
108
			}
109
			# update time
110
			$hours = Utils::intervalDates($now, $place->uPlace);
111
			$place->uPlace = $now;
112
			$initialResources = $place->resources;
113
			$initialDanger = $place->danger;
114
			$maxResources = ceil($place->population / Place::COEFFPOPRESOURCE) * Place::COEFFMAXRESOURCE * ($place->maxDanger + 1);
115
116
			foreach ($hours as $hour) {
117
				$place->danger += Place::REPOPDANGER;
118
				$place->resources += floor(Place::COEFFRESOURCE * $place->population);
119
			}
120
			// The repository method will add the new resources. We have to calculate how many resources have been added
121
			$place->resources = abs($place->resources - $initialResources);
122
			// If the max is reached, we have to add just the difference between the max and init value
123
			if ($place->resources > $maxResources) {
124
				$place->resources = $maxResources - $initialResources;
125
			}
126
			$place->danger = abs($place->danger - $initialDanger);
127
			// Same thing here
128
			if ($place->danger > $place->maxDanger) {
129
				$place->danger = $place->maxDanger - $initialDanger;
130
			}
131
			$repository->updatePlace($place, true);
0 ignored issues
show
Bug introduced by
The method updatePlace() does not exist on Asylamba\Classes\Entity\AbstractRepository. Did you maybe mean update()?

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...
132
		}
133
		$repository->npcQuickfix();
134
		$this->entityManager->commit();
135
		$this->entityManager->clear(Place::class);
136
	}
137
138
	public function updatePlayerPlaces() {
139
		$places = $this->getPlayerPlaces();
140
		$now   = Utils::now();
141
		$repository = $this->entityManager->getRepository(Place::class);
142
		$this->entityManager->beginTransaction();
143
		
144
		foreach ($places as $place) {
145
			if (Utils::interval($place->uPlace, $now, 's') === 0) {
146
				continue;
147
			}
148
			# update time
149
			$hours = Utils::intervalDates($now, $place->uPlace);
150
			$place->uPlace = $now;
151
			$initialResources = $place->resources;
152
			$maxResources = ceil($place->population / Place::COEFFPOPRESOURCE) * Place::COEFFMAXRESOURCE * ($place->maxDanger + 1);
153
			foreach ($hours as $hour) {
154
				$place->resources += floor(Place::COEFFRESOURCE * $place->population);
155
			}
156
			$place->resources = abs($place->resources - $initialResources);
157
			if ($place->resources > $maxResources) {
158
				$place->resources = $maxResources;
159
			}
160
			$repository->updatePlace($place);
0 ignored issues
show
Bug introduced by
The method updatePlace() does not exist on Asylamba\Classes\Entity\AbstractRepository. Did you maybe mean update()?

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...
161
		}
162
		$this->entityManager->commit();
163
		$this->entityManager->clear(Place::class);
164
	}
165
    
166
    /**
167
     * @param Place $place
168
     * @return bool
169
     */
170
    public function turnAsEmptyPlace(Place $place)
171
    {
172
        return $this->entityManager->getRepository(Place::class)->turnAsEmptyPlace($place->getId());
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 turnAsEmptyPlace() does only exist in the following sub-classes of Asylamba\Classes\Entity\AbstractRepository: Asylamba\Modules\Gaia\Repository\PlaceRepository. 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...
173
    }
174
	
175
	public function turnAsSpawnPlace($placeId, $playerId)
176
	{
177
		$this->eventDispatcher->dispatch(new PlaceOwnerChangeEvent($this->get($placeId)));
178
		
179
		return $this->entityManager->getRepository(Place::class)->turnAsSpawnPlace($placeId, $playerId);
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 turnAsSpawnPlace() does only exist in the following sub-classes of Asylamba\Classes\Entity\AbstractRepository: Asylamba\Modules\Gaia\Repository\PlaceRepository. 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...
180
	}
181
182
	/**
183
	 * @param Place $place
184
	 * @param string $case
185
	 * @param Commander $commander
186
	 * @param Report $report
187
	 */
188
	public function sendNotif(Place $place, $case, Commander $commander, $report = NULL) {
189
		switch ($case) {
190
			case Place::CHANGESUCCESS:
191
				$notif = new Notification();
192
				$notif->setRPlayer($commander->getRPlayer());
193
				$notif->setTitle('Déplacement réussi');
194
				$notif->addBeg()
195
					->addTxt('Votre officier ')
196
					->addLnk('fleet/commander-' . $commander->getId(), $commander->getName())
197
					->addTxt(' est arrivé sur ')
198
					->addLnk('map/place-' . $place->id, $place->baseName)
199
					->addTxt('.')
200
					->addEnd();
201
				$this->notificationManager->add($notif);
202
				break;
203
204
			case Place::CHANGEFAIL:
205
				$notif = new Notification();
206
				$notif->setRPlayer($commander->getRPlayer());
207
				$notif->setTitle('Déplacement réussi');
208
				$notif->addBeg()
209
					->addTxt('Votre officier ')
210
					->addLnk('fleet/commander-' . $commander->getId(), $commander->getName())
211
					->addTxt(' s\'est posé sur ')
212
					->addLnk('map/place-' . $place->id, $place->baseName)
213
					->addTxt('. Il est en garnison car il n\'y avait pas assez de place en orbite.')
214
					->addEnd();
215
				$this->notificationManager->add($notif);
216
				break;
217
			case Place::CHANGELOST:
218
				$notif = new Notification();
219
				$notif->setRPlayer($commander->getRPlayer());
220
				$notif->setTitle('Déplacement raté');
221
				$notif->addBeg()
222
					->addTxt('Votre officier ')
223
					->addLnk('fleet/commander-' . $commander->getId(), $commander->getName())
224
					->addTxt(' n\'est pas arrivé sur ')
225
					->addLnk('map/place-' . $place->id, $place->baseName)
226
					->addTxt('. Cette base ne vous appartient pas. Elle a pu être conquise entre temps.')
227
					->addEnd();
228
				$this->notificationManager->add($notif);
229
				break;
230
			case Place::LOOTEMPTYSSUCCESS:
231
				$notif = new Notification();
232
				$notif->setRPlayer($commander->getRPlayer());
233
				$notif->setTitle('Pillage réussi');
234
				$notif->addBeg()
235
					->addTxt('Votre officier ')
236
					->addLnk('fleet/commander-' . $commander->getId() . '/sftr-3', $commander->getName())
237
					->addTxt(' a pillé la planète rebelle située aux coordonnées ')
238
					->addLnk('map/place-' . $place->id, Game::formatCoord($place->xSystem, $place->ySystem, $place->position, $place->rSector))
239
					->addTxt('.')
240
					->addSep()
241
					->addBoxResource('resource', Format::number($commander->getResources()), 'ressources pillées')
242
					->addBoxResource('xp', '+ ' . Format::number($commander->earnedExperience), 'expérience de l\'officier')
243
					->addSep()
244
					->addLnk('fleet/view-archive/report-' . $report, 'voir le rapport')
245
					->addEnd();
246
				$this->notificationManager->add($notif);
247
				break;
248
			case Place::LOOTEMPTYFAIL:
249
				$notif = new Notification();
250
				$notif->setRPlayer($commander->getRPlayer());
251
				$notif->setTitle('Pillage raté');
252
				$notif->addBeg()
253
					->addTxt('Votre officier ')
254
					->addLnk('fleet/view-memorial', $commander->getName())
255
					->addTxt(' est tombé lors de l\'attaque de la planète rebelle située aux coordonnées ')
256
					->addLnk('map/place-' . $place->id, Game::formatCoord($place->xSystem, $place->ySystem, $place->position, $place->rSector))
257
					->addTxt('.')
258
					->addSep()
259
					->addTxt('Il a désormais rejoint le Mémorial. Que son âme traverse l\'Univers dans la paix.')
260
					->addSep()
261
					->addLnk('fleet/view-archive/report-' . $report, 'voir le rapport')
262
					->addEnd();
263
				$this->notificationManager->add($notif);
264
				break;
265
			case Place::LOOTPLAYERWHITBATTLESUCCESS:
266
				$notif = new Notification();
267
				$notif->setRPlayer($commander->getRPlayer());
268
				$notif->setTitle('Pillage réussi');
269
				$notif->addBeg()
270
					->addTxt('Votre officier ')
271
					->addLnk('fleet/commander-' . $commander->getId() . '/sftr-3', $commander->getName())
272
					->addTxt(' a pillé la planète ')
273
					->addLnk('map/place-' . $place->id, $place->baseName)
274
					->addTxt(' appartenant au joueur ')
275
					->addLnk('embassy/player-' . $place->rPlayer, $place->playerName)
276
					->addTxt('.')
277
					->addSep()
278
					->addBoxResource('resource', Format::number($commander->getResources()), 'ressources pillées')
279
					->addBoxResource('xp', '+ ' . Format::number($commander->earnedExperience), 'expérience de l\'officier')
280
					->addSep()
281
					->addLnk('fleet/view-archive/report-' . $report, 'voir le rapport')
282
					->addEnd();
283
				$this->notificationManager->add($notif);
284
285
				$notif = new Notification();
286
				$notif->setRPlayer($place->rPlayer);
287
				$notif->setTitle('Rapport de pillage');
288
				$notif->addBeg()
289
					->addTxt('L\'officier ')
290
					->addStg($commander->getName())
291
					->addTxt(' appartenant au joueur ')
292
					->addLnk('embassy/player-' . $commander->getRPlayer(), $commander->getPlayerName())
293
					->addTxt(' a pillé votre planète ')
294
					->addLnk('map/place-' . $place->id, $place->baseName)
295
					->addTxt('.')
296
					->addSep()
297
					->addBoxResource('resource', Format::number($commander->getResources()), 'ressources pillées')
298
					->addSep()
299
					->addLnk('fleet/view-archive/report-' . $report, 'voir le rapport')
300
					->addEnd();
301
				$this->notificationManager->add($notif);
302
				break;
303
			case Place::LOOTPLAYERWHITBATTLEFAIL:
304
				$notif = new Notification();
305
				$notif->setRPlayer($commander->getRPlayer());
306
				$notif->setTitle('Pillage raté');
307
				$notif->addBeg()
308
					->addTxt('Votre officier ')
309
					->addLnk('fleet/view-memorial', $commander->getName())
310
					->addTxt(' est tombé lors du pillage de la planète ')
311
					->addLnk('map/place-' . $place->id, $place->baseName)
312
					->addTxt(' appartenant au joueur ')
313
					->addLnk('embassy/player-' . $place->rPlayer, $place->playerName)
314
					->addTxt('.')
315
					->addSep()
316
					->addTxt('Il a désormais rejoint le Mémorial. Que son âme traverse l\'Univers dans la paix.')
317
					->addSep()
318
					->addLnk('fleet/view-archive/report-' . $report, 'voir le rapport')
319
					->addEnd();
320
				$this->notificationManager->add($notif);
321
322
				$notif = new Notification();
323
				$notif->setRPlayer($place->rPlayer);
324
				$notif->setTitle('Rapport de combat');
325
				$notif->addBeg()
326
					->addTxt('L\'officier ')
327
					->addStg($commander->getName())
328
					->addTxt(' appartenant au joueur ')
329
					->addLnk('embassy/player-' . $commander->getRPlayer(), $commander->getPlayerName())
330
					->addTxt(' a attaqué votre planète ')
331
					->addLnk('map/place-' . $place->id, $place->baseName)
332
					->addTxt('.')
333
					->addSep()
334
					->addTxt('Vous avez repoussé l\'ennemi avec succès.')
335
					->addSep()
336
					->addLnk('fleet/view-archive/report-' . $report, 'voir le rapport')
337
					->addEnd();
338
				$this->notificationManager->add($notif);
339
				break;
340
			case Place::LOOTPLAYERWHITOUTBATTLESUCCESS:
341
				$notif = new Notification();
342
				$notif->setRPlayer($commander->getRPlayer());
343
				$notif->setTitle('Pillage réussi');
344
				$notif->addBeg()
345
					->addTxt('Votre officier ')
346
					->addLnk('fleet/commander-' . $commander->getId() . '/sftr-3', $commander->getName())
347
					->addTxt(' a pillé la planète non défendue ')
348
					->addLnk('map/place-' . $place->id, $place->baseName)
349
					->addTxt(' appartenant au joueur ')
350
					->addLnk('embassy/player-' . $place->rPlayer, $place->playerName)
351
					->addTxt('.')
352
					->addSep()
353
					->addBoxResource('resource', Format::number($commander->getResources()), 'ressources pillées')
354
					->addBoxResource('xp', '+ ' . Format::number($commander->earnedExperience), 'expérience de l\'officier')
355
					->addEnd();
356
				$this->notificationManager->add($notif);
357
358
				$notif = new Notification();
359
				$notif->setRPlayer($place->rPlayer);
360
				$notif->setTitle('Rapport de pillage');
361
				$notif->addBeg()
362
					->addTxt('L\'officier ')
363
					->addStg($commander->getName())
364
					->addTxt(' appartenant au joueur ')
365
					->addLnk('embassy/player-' . $commander->getRPlayer(), $commander->getPlayerName())
366
					->addTxt(' a pillé votre planète ')
367
					->addLnk('map/place-' . $place->id, $place->baseName)
368
					->addTxt('. Aucune flotte n\'était en position pour la défendre. ')
369
					->addSep()
370
					->addBoxResource('resource', Format::number($commander->getResources()), 'ressources pillées')
371
					->addEnd();
372
				$this->notificationManager->add($notif);
373
				break;
374
			case Place::LOOTLOST:
375
				$notif = new Notification();
376
				$notif->setRPlayer($commander->getRPlayer());
377
				$notif->setTitle('Erreur de coordonnées');
378
				$notif->addBeg()
379
					->addTxt('Votre officier ')
380
					->addLnk('fleet/commander-' . $commander->getId() . '/sftr-3', $commander->getName())
381
					->addTxt(' n\'a pas attaqué la planète ')
382
					->addLnk('map/place-' . $place->id, $place->baseName)
383
					->addTxt(' car son joueur est de votre faction, sous la protection débutant ou un allié.')
384
					->addEnd();
385
				$this->notificationManager->add($notif);
386
				break;
387
			case Place::CONQUEREMPTYSSUCCESS:
388
				$notif = new Notification();
389
				$notif->setRPlayer($commander->getRPlayer());
390
				$notif->setTitle('Colonisation réussie');
391
				$notif->addBeg()
392
					->addTxt('Votre officier ')
393
					->addLnk('fleet/commander-' . $commander->getId() . '/sftr-3', $commander->getName())
394
					->addTxt(' a colonisé la planète rebelle située aux coordonnées ')  
395
					->addLnk('map/place-' . $place->id , Game::formatCoord($place->xSystem, $place->ySystem, $place->position, $place->rSector) . '.')
0 ignored issues
show
Coding Style introduced by
Space found before comma in function call
Loading history...
396
					->addBoxResource('xp', '+ ' . Format::number($commander->earnedExperience), 'expérience de l\'officier')
397
					->addTxt('Votre empire s\'étend, administrez votre ')
398
					->addLnk('bases/base-' . $place->id, 'nouvelle planète')
399
					->addTxt('.')
400
					->addSep()
401
					->addLnk('fleet/view-archive/report-' . $report, 'voir le rapport')
402
					->addEnd();
403
				$this->notificationManager->add($notif);
404
				break;
405
			case Place::CONQUEREMPTYFAIL:
406
				$notif = new Notification();
407
				$notif->setRPlayer($commander->getRPlayer());
408
				$notif->setTitle('Colonisation ratée');
409
				$notif->addBeg()
410
					->addTxt('Votre officier ')
411
					->addLnk('fleet/view-memorial', $commander->getName())
412
					->addTxt(' est tombé lors de l\'attaque de la planète rebelle située aux coordonnées ')
413
					->addLnk('map/place-' . $place->id, Game::formatCoord($place->xSystem, $place->ySystem, $place->position, $place->rSector))
414
					->addTxt('.')
415
					->addSep()
416
					->addTxt('Il a désormais rejoint le Mémorial. Que son âme traverse l\'Univers dans la paix.')
417
					->addSep()
418
					->addLnk('fleet/view-archive/report-' . $report, 'voir le rapport')
419
					->addEnd();
420
				$this->notificationManager->add($notif);
421
				break;
422
			case Place::CONQUERPLAYERWHITOUTBATTLESUCCESS:
423
				$notif = new Notification();
424
				$notif->setRPlayer($commander->getRPlayer());
425
				$notif->setTitle('Conquête réussie');
426
				$notif->addBeg()
427
					->addTxt('Votre officier ')
428
					->addLnk('fleet/commander-' . $commander->getId() . '/sftr-3', $commander->getName())
429
					->addTxt(' a conquis la planète non défendue ')
430
					->addLnk('map/place-' . $place->id, $place->baseName)
431
					->addTxt(' appartenant au joueur ')
432
					->addLnk('embassy/player-' . $place->rPlayer, $place->playerName)
433
					->addTxt('.')
434
					->addSep()
435
					->addBoxResource('xp', '+ ' . Format::number($commander->earnedExperience), 'expérience de l\'officier')
436
					->addTxt('Elle est désormais votre, vous pouvez l\'administrer ')
437
					->addLnk('bases/base-' . $place->id, 'ici')
438
					->addTxt('.')
439
					->addEnd();
440
				$this->notificationManager->add($notif);
441
442
				$notif = new Notification();
443
				$notif->setRPlayer($place->rPlayer);
444
				$notif->setTitle('Planète conquise');
445
				$notif->addBeg()
446
					->addTxt('L\'officier ')
447
					->addStg($commander->getName())
448
					->addTxt(' appartenant au joueur ')
449
					->addLnk('embassy/player-' . $commander->getRPlayer(), $commander->getPlayerName())
450
					->addTxt(' a conquis votre planète non défendue ')
451
					->addLnk('map/place-' . $place->id, $place->baseName)
452
					->addTxt('.')
453
					->addSep()
454
					->addTxt('Impliquez votre faction dans une action punitive envers votre assaillant.')
455
					->addEnd();
456
				$this->notificationManager->add($notif);
457
				break;
458
			case Place::CONQUERLOST:
459
				$notif = new Notification();
460
				$notif->setRPlayer($commander->getRPlayer());
461
				$notif->setTitle('Erreur de coordonnées');
462
				$notif->addBeg()
463
					->addTxt('Votre officier ')
464
					->addLnk('fleet/commander-' . $commander->getId() . '/sftr-3', $commander->getName())
465
					->addTxt(' n\'a pas attaqué la planète ')
466
					->addLnk('map/place-' . $place->id, $place->baseName)
467
					->addTxt(' car le joueur est dans votre faction, sous la protection débutant ou votre allié.')
468
					->addEnd();
469
				$this->notificationManager->add($notif);
470
				break;
471
			case Place::COMEBACK:
472
				$notif = new Notification();
473
				$notif->setRPlayer($commander->getRPlayer());
474
				$notif->setTitle('Rapport de retour');
475
				$notif->addBeg()
476
					->addTxt('Votre officier ')
477
					->addLnk('fleet/commander-' . $commander->getId() . '/sftr-3', $commander->getName())
478
					->addTxt(' est de retour sur votre base ')
479
					->addLnk('map/place-' . $commander->getRBase(), $commander->getBaseName())
480
					->addTxt(' et rapporte ')
481
					->addStg(Format::number($commander->getResources()))
482
					->addTxt(' ressources à vos entrepôts.')
483
					->addEnd();
484
				$this->notificationManager->add($notif);
485
				break;
486
			
487
			default: break;
0 ignored issues
show
Coding Style introduced by
The default body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a default statement must start on the line immediately following the statement.

switch ($expr) {
    default:
        doSomething(); //right
        break;
}


switch ($expr) {
    default:

        doSomething(); //wrong
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
488
		}
489
	}
490
491
	/**
492
	 * @param Place $place
493
	 * @param string $case
494
	 * @param Commander $commander
495
	 * @param array $reports
496
	 */
497
	public function sendNotifForConquest(Place $place, $case, $commander, $reports = array()) {
498
		$nbrBattle = count($reports);
499
		switch($case) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after SWITCH keyword; 0 found
Loading history...
500
			case Place::CONQUERPLAYERWHITBATTLESUCCESS:
501
				$notif = new Notification();
502
				$notif->setRPlayer($commander->getRPlayer());
503
				$notif->setTitle('Conquête réussie');
504
				$notif->addBeg()
505
					->addTxt('Votre officier ')
506
					->addLnk('fleet/commander-' . $commander->getId() . '/sftr-3', $commander->getName())
507
					->addTxt(' a conquis la planète ')
508
					->addLnk('map/place-' . $place->id, $place->baseName)
509
					->addTxt(' appartenant au joueur ')
510
					->addLnk('embassy/player-' . $place->rPlayer, $place->playerName)
511
					->addTxt('.')
512
					->addSep()
513
					->addTxt($nbrBattle . Format::addPlural($nbrBattle, ' combats ont eu lieu.', ' seul combat a eu lieu'))
514
					->addSep()
515
					->addBoxResource('xp', '+ ' . Format::number($commander->earnedExperience), 'expérience de l\'officier')
516
					->addSep()
517
					->addTxt('Elle est désormais vôtre, vous pouvez l\'administrer ')
518
					->addLnk('bases/base-' . $place->id, 'ici')
519
					->addTxt('.');
520
				for ($i = 0; $i < $nbrBattle; $i++) {
521
					$notif->addSep();
522
					$notif->addLnk('fleet/view-archive/report-' . $reports[$i], 'voir le ' . Format::ordinalNumber($i + 1) . ' rapport');
523
				}
524
				$notif->addEnd();
525
				$this->notificationManager->add($notif);
526
527
				$notif = new Notification();
528
				$notif->setRPlayer($place->rPlayer);
529
				$notif->setTitle('Planète conquise');
530
				$notif->addBeg()
531
					->addTxt('L\'officier ')
532
					->addStg($commander->getName())
533
					->addTxt(' appartenant au joueur ')
534
					->addLnk('embassy/player-' . $commander->getRPlayer(), $commander->getPlayerName())
535
					->addTxt(' a conquis votre planète ')
536
					->addLnk('map/place-' . $place->id, $place->baseName)
537
					->addTxt('.')
538
					->addSep()
539
					->addTxt($nbrBattle . Format::addPlural($nbrBattle, ' combats ont eu lieu.', ' seul combat a eu lieu'))
540
					->addSep()
541
					->addTxt('Impliquez votre faction dans une action punitive envers votre assaillant.');
542
				for ($i = 0; $i < $nbrBattle; $i++) {
543
					$notif->addSep();
544
					$notif->addLnk('fleet/view-archive/report-' . $reports[$i], 'voir le ' . Format::ordinalNumber($i + 1) . ' rapport');
545
				}
546
				$notif->addEnd();
547
				$this->notificationManager->add($notif);
548
				break;
549
			case Place::CONQUERPLAYERWHITBATTLEFAIL:
550
				$notif = new Notification();
551
				$notif->setRPlayer($commander->getRPlayer());
552
				$notif->setTitle('Conquête ratée');
553
				$notif->addBeg()
554
					->addTxt('Votre officier ')
555
					->addLnk('fleet/view-memorial/', $commander->getName())
556
					->addTxt(' est tombé lors de la tentive de conquête de la planète ')
557
					->addLnk('map/place-' . $place->id, $place->baseName)
558
					->addTxt(' appartenant au joueur ')
559
					->addLnk('embassy/player-' . $place->rPlayer, $place->playerName)
560
					->addTxt('.')
561
					->addSep()
562
					->addTxt($nbrBattle . Format::addPlural($nbrBattle, ' combats ont eu lieu.', ' seul combat a eu lieu'))
563
					->addSep()
564
					->addTxt('Il a désormais rejoint de Mémorial. Que son âme traverse l\'Univers dans la paix.');
565
				for ($i = 0; $i < $nbrBattle; $i++) {
566
					$notif->addSep();
567
					$notif->addLnk('fleet/view-archive/report-' . $reports[$i], 'voir le ' . Format::ordinalNumber($i + 1) . ' rapport');
568
				}
569
				$notif->addEnd();
570
				$this->notificationManager->add($notif);
571
572
				$notif = new Notification();
573
				$notif->setRPlayer($place->rPlayer);
574
				$notif->setTitle('Rapport de combat');
575
				$notif->addBeg()
576
					->addTxt('L\'officier ')
577
					->addStg($commander->getName())
578
					->addTxt(' appartenant au joueur ')
579
					->addLnk('embassy/player-' . $commander->getRPlayer(), $commander->getPlayerName())
580
					->addTxt(' a tenté de conquérir votre planète ')
581
					->addLnk('map/place-' . $place->id, $place->baseName)
582
					->addTxt('.')
583
					->addSep()
584
					->addTxt($nbrBattle . Format::addPlural($nbrBattle, ' combats ont eu lieu.', ' seul combat a eu lieu'))
585
					->addSep()
586
					->addTxt('Vous avez repoussé l\'ennemi avec succès. Bravo !');
587
				for ($i = 0; $i < $nbrBattle; $i++) {
588
					$notif->addSep();
589
					$notif->addLnk('fleet/view-archive/report-' . $reports[$i], 'voir le ' . Format::ordinalNumber($i + 1) . ' rapport');
590
				}
591
				$notif->addEnd();
592
				$this->notificationManager->add($notif);
593
				break;
594
595
			default: break;
0 ignored issues
show
Coding Style introduced by
The default body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a default statement must start on the line immediately following the statement.

switch ($expr) {
    default:
        doSomething(); //right
        break;
}


switch ($expr) {
    default:

        doSomething(); //wrong
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
596
		}
597
	}
598
}