Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
9 / 9 |
|
91.67% |
11 / 12 |
|
25.00% |
2 / 8 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| Discovery | |
100.00% |
9 / 9 |
|
91.67% |
11 / 12 |
|
25.00% |
2 / 8 |
|
100.00% |
1 / 1 |
10.75 | |
100.00% |
1 / 1 |
| create | |
100.00% |
9 / 9 |
|
91.67% |
11 / 12 |
|
25.00% |
2 / 8 |
|
100.00% |
1 / 1 |
10.75 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Celemas\Core\Factory; |
| 6 | |
| 7 | use Celemas\Core\Exception\RuntimeException; |
| 8 | |
| 9 | /** @api */ |
| 10 | final class Discovery |
| 11 | { |
| 12 | /** @var array<class-string<Factory>, non-empty-array<int, non-empty-string>> */ |
| 13 | private const CANDIDATES = [ |
| 14 | Nyholm::class => [ |
| 15 | 'Nyholm\\Psr7\\Factory\\Psr17Factory', |
| 16 | 'Nyholm\\Psr7Server\\ServerRequestCreator', |
| 17 | ], |
| 18 | Guzzle::class => [ |
| 19 | 'GuzzleHttp\\Psr7\\HttpFactory', |
| 20 | ], |
| 21 | Laminas::class => [ |
| 22 | 'Laminas\\Diactoros\\RequestFactory', |
| 23 | ], |
| 24 | ]; |
| 25 | |
| 26 | public static function create(): Factory |
| 27 | { |
| 28 | foreach (self::CANDIDATES as $factoryClass => $probeClasses) { |
| 29 | foreach ($probeClasses as $probeClass) { |
| 30 | if (!class_exists($probeClass)) { |
| 31 | continue 2; |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | return new $factoryClass(); |
| 36 | } |
| 37 | |
| 38 | throw new RuntimeException( |
| 39 | 'No supported PSR-7 implementation found. Install one of: ' |
| 40 | . 'nyholm/psr7 with nyholm/psr7-server, guzzlehttp/psr7, or laminas/laminas-diactoros', |
| 41 | ); |
| 42 | } |
| 43 | } |
Below are the source code lines that represent each code branch as identified by Xdebug. Please note a branch is not
necessarily coterminous with a line, a line may contain multiple branches and therefore show up more than once.
Please also be aware that some branches may be implicit rather than explicit, e.g. an if statement
always has an else as part of its logical flow even if you didn't write one.
| 28 | foreach (self::CANDIDATES as $factoryClass => $probeClasses) { |
| 28 | foreach (self::CANDIDATES as $factoryClass => $probeClasses) { |
| 28 | foreach (self::CANDIDATES as $factoryClass => $probeClasses) { |
| 29 | foreach ($probeClasses as $probeClass) { |
| 29 | foreach ($probeClasses as $probeClass) { |
| 30 | if (!class_exists($probeClass)) { |
| 30 | if (!class_exists($probeClass)) { |
| 30 | if (!class_exists($probeClass)) { |
| 30 | if (!class_exists($probeClass)) { |
| 31 | continue 2; |
| 29 | foreach ($probeClasses as $probeClass) { |
| 29 | foreach ($probeClasses as $probeClass) { |
| 30 | if (!class_exists($probeClass)) { |
| 31 | continue 2; |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | return new $factoryClass(); |
| 28 | foreach (self::CANDIDATES as $factoryClass => $probeClasses) { |
| 29 | foreach ($probeClasses as $probeClass) { |
| 30 | if (!class_exists($probeClass)) { |
| 31 | continue 2; |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | return new $factoryClass(); |
| 36 | } |
| 37 | |
| 38 | throw new RuntimeException( |
| 39 | 'No supported PSR-7 implementation found. Install one of: ' |
| 40 | . 'nyholm/psr7 with nyholm/psr7-server, guzzlehttp/psr7, or laminas/laminas-diactoros', |
| 41 | ); |
| 42 | } |