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.

CommercialShippingManager::render()   F
last analyzed

Complexity

Conditions 14
Paths 248

Size

Total Lines 88
Code Lines 69

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 14
eloc 69
nc 248
nop 1
dl 0
loc 88
rs 3.7873
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * CommercialShippingManager
5
 *
6
 * @author Jacky Casas
7
 * @copyright Expansion - le jeu
8
 *
9
 * @package Athena
10
 * @version 19.11.13
11
 **/
12
namespace Asylamba\Modules\Athena\Manager;
13
14
use Asylamba\Modules\Athena\Manager\OrbitalBaseManager;
15
use Asylamba\Modules\Hermes\Manager\NotificationManager;
16
use Asylamba\Classes\Library\Utils;
17
use Asylamba\Classes\Entity\EntityManager;
18
use Asylamba\Modules\Athena\Model\CommercialShipping;
19
use Asylamba\Modules\Athena\Model\Transaction;
20
use Asylamba\Classes\Library\Format;
21
use Asylamba\Classes\Library\Session\SessionWrapper;
22
use Asylamba\Modules\Athena\Resource\ShipResource;
23
use Asylamba\Modules\Hermes\Model\Notification;
24
use Asylamba\Modules\Ares\Resource\CommanderResources;
25
use Asylamba\Modules\Ares\Model\Commander;
26
use Asylamba\Classes\Exception\ErrorException;
27
use Asylamba\Classes\Scheduler\RealTimeActionScheduler;
28
29
class CommercialShippingManager {
30
	/** @var EntityManager **/
31
	protected $entityManager;
32
	/** @var OrbitalBaseManager **/
33
	protected $orbitalBaseManager;
34
	/** @var NotificationManager **/
35
	protected $notificationManager;
36
	/** @var RealTimeActionScheduler **/
37
	protected $realtimeActionScheduler;
38
	/** @var SessionWrapper **/
39
	protected $sessionWrapper;
40
	
41
	/**
42
	 * @param EntityManager $entityManager
43
	 * @param OrbitalBaseManager $orbitalBaseManager
44
	 * @param NotificationManager $notificationManager
45
	 * @param RealTimeActionScheduler $realtimeActionScheduler
46
	 * @param SessionWrapper $session
47
	 */
48
	public function __construct(
49
		EntityManager $entityManager,
50
		OrbitalBaseManager $orbitalBaseManager,
51
		NotificationManager $notificationManager,
52
		RealTimeActionScheduler $realtimeActionScheduler,
53
		SessionWrapper $session
54
	) {
55
		$this->entityManager = $entityManager;
56
		$this->orbitalBaseManager = $orbitalBaseManager;
57
		$this->notificationManager = $notificationManager;
58
		$this->realtimeActionScheduler = $realtimeActionScheduler;
59
		$this->sessionWrapper = $session;
60
	}
61
	
62
	public function scheduleShippings()
63
	{
64
		$shippings = $this->entityManager->getRepository(CommercialShipping::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...
65
		
66
		foreach ($shippings as $commercialShipping) {
67
			$this->realtimeActionScheduler->schedule(
68
				'athena.orbital_base_manager',
69
				'uCommercialShipping',
70
				$commercialShipping,
71
				$commercialShipping->getArrivedAt()
72
			);
73
		}
74
	}
75
	
76
	/**
77
	 * @param int $id
78
	 * @return CommercialShipping
79
	 */
80
	public function get($id)
81
	{
82
		return $this->entityManager->getRepository(CommercialShipping::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...
83
	}
84
	
85
	/**
86
	 * @param int $id
87
	 * @return CommercialShipping
88
	 */
89
	public function getByTransactionId($id)
90
	{
91
		return $this->entityManager->getRepository(CommercialShipping::class)->getByTransactionId($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 getByTransactionId() does only exist in the following sub-classes of Asylamba\Classes\Entity\AbstractRepository: Asylamba\Modules\Athena\...rcialShippingRepository. 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...
92
	}
93
	
94
	/**
95
	 * @param type $orbitalBaseId
96
	 * @return array
97
	 */
98
	public function getByBase($orbitalBaseId)
99
	{
100
		return $this->entityManager->getRepository(CommercialShipping::class)->getByBase($orbitalBaseId);
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 getByBase() does only exist in the following sub-classes of Asylamba\Classes\Entity\AbstractRepository: Asylamba\Modules\Athena\...mmercialRouteRepository, Asylamba\Modules\Athena\...rcialShippingRepository. 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...
101
	}
102
103
	/**
104
	 * @param CommercialShipping $commercialShipping
105
	 */
106
	public function add(CommercialShipping $commercialShipping) {
107
		$this->entityManager->persist($commercialShipping);
108
		$this->entityManager->flush($commercialShipping);
109
		
110
		$this->realtimeActionScheduler->schedule(
111
			'athena.orbital_base_manager',
112
			'uCommercialShipping',
113
			$commercialShipping,
0 ignored issues
show
Documentation introduced by
$commercialShipping is of type object<Asylamba\Modules\...del\CommercialShipping>, 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...
114
			$commercialShipping->getArrivedAt()
115
		);
116
	}
117
118
	public function deliver(CommercialShipping $commercialShipping, $transaction, $destOB, $commander) {
119
		if ($transaction !== NULL AND $transaction->statement == Transaction::ST_COMPLETED) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, PHP keywords should be in lowercase; expected and, but found AND.
Loading history...
Coding Style introduced by
Blank line found at start of control structure
Loading history...
120
121
			switch ($transaction->type) {
122
				case Transaction::TYP_RESOURCE:
123
					$this->orbitalBaseManager->increaseResources($destOB, $transaction->quantity, TRUE);
124
125
					# notif pour l'acheteur
126
					$n = new Notification();
127
					$n->setRPlayer($destOB->getRPlayer());
128
					$n->setTitle('Ressources reçues');
129
					$n->addBeg()->addTxt('Vous avez reçu les ' . $transaction->quantity . ' ressources que vous avez achetées au marché.');
130
					$n->addEnd();
131
					$this->notificationManager->add($n);
132
133
					break;
134
				case Transaction::TYP_SHIP:
135
					$this->orbitalBaseManager->addShipToDock($destOB, $transaction->identifier, $transaction->quantity);
136
137
					# notif pour l'acheteur
138
					$n = new Notification();
139
					$n->setRPlayer($destOB->getRPlayer());
140
					if ($commercialShipping->resourceTransported == NULL) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $commercialShipping->resourceTransported of type integer|null against null; this is ambiguous if the integer can be zero. Consider using a strict comparison === instead.
Loading history...
141
						# transaction
142
						if ($transaction->quantity == 1) {
143
							$n->setTitle('Vaisseau reçu');
144
							$n->addBeg()->addTxt('Vous avez reçu le vaisseau de type ' . ShipResource::getInfo($transaction->identifier, 'codeName') . ' que vous avez acheté au marché.');
145
							$n->addSep()->addTxt('Il a été ajouté à votre hangar.');
146
						} else {
147
							$n->setTitle('Vaisseaux reçus');
148
							$n->addBeg()->addTxt('Vous avez reçu les ' . $transaction->quantity . ' vaisseaux de type ' . ShipResource::getInfo($transaction->identifier, 'codeName') . ' que vous avez achetés au marché.');
149
							$n->addSep()->addTxt('Ils ont été ajoutés à votre hangar.');
150
						}
151
					} else {
152
						# ships sending
153
						if ($transaction->quantity == 1) {
154
							$n->setTitle('Vaisseau reçu');
155
							$n->addBeg()->addTxt('Vous avez reçu le vaisseau de type ' . ShipResource::getInfo($transaction->identifier, 'codeName') . ' envoyé par un marchand galactique.');
156
							$n->addSep()->addTxt('Il a été ajouté à votre hangar.');
157
						} else {
158
							$n->setTitle('Vaisseaux reçus');
159
							$n->addBeg()->addTxt('Vous avez reçu les ' . $transaction->quantity . ' vaisseaux de type ' . ShipResource::getInfo($transaction->identifier, 'codeName') . ' envoyés par un marchand galactique.');
160
							$n->addSep()->addTxt('Ils ont été ajoutés à votre hangar.');
161
						}
162
					}
163
					$n->addEnd();
164
					$this->notificationManager->add($n);
165
					break;
166
				case Transaction::TYP_COMMANDER:
167
					$commander->setStatement(Commander::RESERVE);
168
					$commander->setRPlayer($destOB->getRPlayer());
169
					$commander->setRBase($commercialShipping->rBaseDestination);
170
171
					# notif pour l'acheteur
172
					$n = new Notification();
173
					$n->setRPlayer($destOB->getRPlayer());
174
					$n->setTitle('Commandant reçu');
175
					$n->addBeg()->addTxt('Le commandant ' . $commander->getName() . ' que vous avez acheté au marché est bien arrivé.');
176
					$n->addSep()->addTxt('Il se trouve pour le moment dans votre école de commandement');
177
					$n->addEnd();
178
					$this->notificationManager->add($n);
179
					break;
180
				default:
181
					throw new ErrorException('type de transaction inconnue dans deliver()');
182
			}
183
184
			$commercialShipping->statement = CommercialShipping::ST_MOVING_BACK;
185
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
186
		} elseif ($transaction === NULL AND $commercialShipping->rTransaction == NULL AND $commercialShipping->resourceTransported != NULL) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $commercialShipping->resourceTransported of type integer|null against null; this is ambiguous if the integer can be zero. Consider using a strict comparison !== instead.
Loading history...
Coding Style introduced by
As per coding-style, PHP keywords should be in lowercase; expected and, but found AND.
Loading history...
187
			# resource sending
188
189
			$this->orbitalBaseManager->increaseResources($destOB, $commercialShipping->resourceTransported, TRUE);
190
191
			# notif for the player who receive the resources
192
			$n = new Notification();
193
			$n->setRPlayer($destOB->getRPlayer());
194
			$n->setTitle('Ressources reçues');
195
			$n->addBeg()->addTxt('Vous avez bien reçu les ' . $commercialShipping->resourceTransported . ' ressources sur votre base orbitale ' . $destOB->name . '.');
196
			$n->addEnd();
197
			$this->notificationManager->add($n);
198
199
			$commercialShipping->statement = CommercialShipping::ST_MOVING_BACK;
200
		} else {
201
			throw new ErrorException('impossible de délivrer ce chargement');
202
		}
203
	}
204
205
	public function render(CommercialShipping $commercialShipping) {
206
		switch ($commercialShipping->typeOfTransaction) {
207
			case Transaction::TYP_RESOURCE: $class = 'resources'; break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

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

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //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...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
208
			case Transaction::TYP_COMMANDER: $class = 'commander'; break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

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

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //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...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
209
			case Transaction::TYP_SHIP:
210
				$class = 'ship';
211
				break;
212
			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...
213
		}
214
215
		echo '<div class="transaction ' . $class . '">';
0 ignored issues
show
Bug introduced by
The variable $class does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
216
			if ($commercialShipping->statement != CommercialShipping::ST_MOVING_BACK) {
217
				echo '<div class="product">';
218
					if ($commercialShipping->statement == CommercialShipping::ST_WAITING) {
219
						echo '<a href="' . Format::actionBuilder('canceltransaction', $this->sessionWrapper->get('token'), ['rtransaction' => $commercialShipping->rTransaction]) . '" class="hb lt right-link" title="supprimer cette offre coûtera ' . Format::number(floor($commercialShipping->price * Transaction::PERCENTAGE_TO_CANCEL / 100)) . ' crédits">×</a>';
220
					}
221
					if ($commercialShipping->typeOfTransaction == Transaction::TYP_RESOURCE) {
222
						echo '<img src="' . MEDIA . 'market/resources-pack-' . Transaction::getResourcesIcon($commercialShipping->quantity) . '.png" alt="" class="picto" />';
223
						echo '<div class="offer">';
224
							if ($commercialShipping->resourceTransported == NULL) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $commercialShipping->resourceTransported of type integer|null against null; this is ambiguous if the integer can be zero. Consider using a strict comparison === instead.
Loading history...
225
								# transaction
226
								echo Format::numberFormat($commercialShipping->quantity) . ' <img src="' . MEDIA . 'resources/resource.png" alt="" class="icon-color" />';
227
							} else {
228
								# resources sending
229
								echo Format::numberFormat($commercialShipping->resourceTransported) . ' <img src="' . MEDIA . 'resources/resource.png" alt="" class="icon-color" />';
230
							}
231
						echo '</div>';
232
					} elseif ($commercialShipping->typeOfTransaction == Transaction::TYP_COMMANDER) {
233
						echo '<img src="' . MEDIA . 'commander/small/' . $commercialShipping->commanderAvatar . '.png" alt="" class="picto" />';
234
						echo '<div class="offer">';
235
							echo '<strong>' . CommanderResources::getInfo($commercialShipping->commanderLevel, 'grade') . ' ' . $commercialShipping->commanderName . '</strong>';
236
							echo '<em>' . Format::numberFormat($commercialShipping->commanderExperience) . ' xp | ' . $commercialShipping->commanderVictory . ' victoire' . Format::addPlural($commercialShipping->commanderVictory) . '</em>';
237
						echo '</div>';
238
					} elseif ($commercialShipping->typeOfTransaction == Transaction::TYP_SHIP) {
239
						echo '<img src="' . MEDIA . 'ship/picto/ship' . $commercialShipping->identifier . '.png" alt="" class="picto" />';
240
						echo '<div class="offer">';
241
							echo '<strong>' . $commercialShipping->quantity . ' ' . ShipResource::getInfo($commercialShipping->identifier, 'codeName') . Format::plural($commercialShipping->quantity) . '</strong>';
242
							echo '<em>' . ShipResource::getInfo($commercialShipping->identifier, 'name') . ' / ' . ShipResource::getInfo($commercialShipping->identifier, 'pev') . ' pev</em>';
243
						echo '</div>';
244
					}
245
246
					if ($commercialShipping->resourceTransported === NULL) {
247
						# transaction
248
						echo '<div class="for">';
249
							echo '<span>pour</span>';
250
						echo '</div>';
251
						echo '<div class="price">';
252
							echo Format::numberFormat($commercialShipping->price) . ' <img src="' . MEDIA . 'resources/credit.png" alt="" class="icon-color" />';
253
						echo '</div>';
254
					} elseif ($commercialShipping->resourceTransported == 0) {
255
						# ships sending
256
						echo '<div class="for"><span></span></div>';
257
						echo '<div class="price">';
258
							echo 'envoi de vaisseaux';
259
						echo '</div>';
260
					} else {
261
						# resources sending
262
						echo '<div class="for"><span></span></div>';
263
						echo '<div class="price">';
264
							echo 'envoi de ressources';
265
						echo '</div>';
266
					}
267
				echo '</div>';
268
			}
269
270
			$totalTime   = Utils::interval($commercialShipping->dDeparture, $commercialShipping->dArrival, 's');
271
			$currentTime = Utils::interval(Utils::now(), $commercialShipping->dDeparture, 's');
272
273
			echo ($commercialShipping->statement != CommercialShipping::ST_WAITING)
274
				?'<div class="shipping progress" data-progress-total-time="' . $totalTime . '" data-progress-current-time="' . ($totalTime - $currentTime) . '" data-progress-output="lite">'
275
				: '<div class="shipping">';
276
				echo '<span class="progress-container">';
277
					echo '<span style="width: ' . Format::percent($currentTime, $totalTime) . '%;" class="progress-bar"></span>';
278
				echo '</span>';
279
280
				echo '<div class="ships">';
281
					echo $commercialShipping->shipQuantity;
282
					echo '<img src="' . MEDIA . 'resources/transport.png" alt="" class="icon-color" />';
283
				echo '</div>';
284
285
				if ($commercialShipping->statement == CommercialShipping::ST_WAITING) {
286
					echo '<div class="time">à quai</div>';
287
				} else {
288
					echo '<div class="time progress-text"></div>';
289
				}
290
			echo '</div>';
291
		echo '</div>';
292
	}
293
}