Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
93.75% |
15 / 16 |
|
85.71% |
12 / 14 |
|
81.82% |
9 / 11 |
|
88.89% |
8 / 9 |
CRAP | |
0.00% |
0 / 1 |
| Application | |
93.75% |
15 / 16 |
|
85.71% |
12 / 14 |
|
81.82% |
9 / 11 |
|
88.89% |
8 / 9 |
11.73 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getServerType | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getGinaRolePrefix | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getUrl | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isServerLocal | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getEnvironment | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isDebug | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getVersion | |
80.00% |
4 / 5 |
|
66.67% |
4 / 6 |
|
33.33% |
1 / 3 |
|
0.00% |
0 / 1 |
5.67 | |||
| getUser | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App; |
| 4 | |
| 5 | use App\Security\User; |
| 6 | use Symfony\Bundle\SecurityBundle\Security; |
| 7 | |
| 8 | /** |
| 9 | * @phpstan-type Settings array{ |
| 10 | * APP_SERVER_TYPE?:string|null, |
| 11 | * APP_ROLE_PREFIX?:string|null, |
| 12 | * APP_URL?:string|null |
| 13 | * } |
| 14 | */ |
| 15 | class Application |
| 16 | { |
| 17 | public const string FORMAT_SHORT_DATE = 'd.m.Y'; |
| 18 | public const string FORMAT_SHORT_DATETIME = 'd.m.Y - H:i'; |
| 19 | public const string FORMAT_SHORT_TIME = 'H:i:s'; |
| 20 | |
| 21 | private Security $security; |
| 22 | private Kernel $kernel; |
| 23 | /** @var Settings */ |
| 24 | private array $settings; |
| 25 | |
| 26 | /** |
| 27 | * @param Settings $settings |
| 28 | */ |
| 29 | public function __construct(Security $security, Kernel $kernel, array $settings) |
| 30 | { |
| 31 | $this->security = $security; |
| 32 | $this->kernel = $kernel; |
| 33 | $this->settings = $settings; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Return type of server (it's not symfony environment, don't confuse it). |
| 38 | * |
| 39 | * return values: 'prod', 'rec','dev' ou 'local' |
| 40 | */ |
| 41 | public function getServerType(): string |
| 42 | { |
| 43 | /** @var array{APP_SERVER_TYPE?:string|null} $_ENV */ |
| 44 | $serverType = $this->settings['APP_SERVER_TYPE'] ?? 'prod'; |
| 45 | |
| 46 | return mb_strtolower($serverType); |
| 47 | } |
| 48 | |
| 49 | public function getGinaRolePrefix(): string |
| 50 | { |
| 51 | return $this->settings['APP_ROLE_PREFIX'] ?? ''; |
| 52 | } |
| 53 | |
| 54 | public function getUrl(): string |
| 55 | { |
| 56 | return $this->settings['APP_URL'] ?? ''; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Indication if the application run on a local PC. |
| 61 | */ |
| 62 | public function isServerLocal(): bool |
| 63 | { |
| 64 | return 'local' === $this->getServerType(); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Return the symfony current environment. |
| 69 | * |
| 70 | * return values: 'prod', 'dev' |
| 71 | */ |
| 72 | public function getEnvironment(): string |
| 73 | { |
| 74 | return $this->kernel->getEnvironment(); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Return indication of the symfony debug mode. |
| 79 | */ |
| 80 | public function isDebug(): bool |
| 81 | { |
| 82 | return $this->kernel->isDebug(); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * @throws ExceptionApplication |
| 87 | */ |
| 88 | public function getVersion(): string |
| 89 | { |
| 90 | $propertiesFile = __DIR__ . '/../release.properties'; |
| 91 | $propertiesContent = parse_ini_file($propertiesFile); |
| 92 | if (!isset($propertiesContent['version'])) { |
| 93 | throw new ExceptionApplication("'version' manquante dans le fichier release.properties"); |
| 94 | } |
| 95 | |
| 96 | return is_string($propertiesContent['version']) ? $propertiesContent['version'] : ''; |
| 97 | } |
| 98 | |
| 99 | public function getUser(): ?User |
| 100 | { |
| 101 | /** @var User */ |
| 102 | return $this->security->getToken()?->getUser(); |
| 103 | } |
| 104 | } |