Passed
Branch master (aecce8)
by Brice
05:03
created

ApiRouting   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 32
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getRoutingCachePath() 0 8 2
A create() 0 11 1
1
<?php
2
3
namespace JobQueue\Application\Http;
4
5
use function FastRoute\cachedDispatcher;
6
use FastRoute\Dispatcher;
7
use FastRoute\RouteCollector;
8
use JobQueue\Infrastructure\Environment;
9
10
final class ApiRouting
11
{
12
    /**
13
     *
14
     * @return Dispatcher
15
     */
16
    public static function create(): Dispatcher
17
    {
18
        return cachedDispatcher(function (RouteCollector $r)
19
        {
20
            $r->get(  '/tasks',             ListTasks::class );
21
            $r->post( '/tasks',             AddTask::class   );
22
            $r->get(  '/task/{identifier}', ShowTask::class  );
23
24
        }, [
25
            'cacheFile' => self::getRoutingCachePath(),
26
            'cacheDisabled' => !Environment::isProd(),
27
        ]);
28
    }
29
30
    /**
31
     *
32
     * @return string
33
     */
34
    private static function getRoutingCachePath(): string
35
    {
36
        // Get dir path from environment variables
37
        if (!$dir = getenv('JOBQUEUE_CACHE_PATH')) {
38
            $dir = sys_get_temp_dir();
39
        }
40
41
        return sprintf('%s/jobqueue_routing.php', $dir);
0 ignored issues
show
Bug introduced by
It seems like $dir can also be of type array; however, parameter $args of sprintf() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

41
        return sprintf('%s/jobqueue_routing.php', /** @scrutinizer ignore-type */ $dir);
Loading history...
42
    }
43
}
44