Test Failed
Push — master ( fa8c20...ab35ba )
by Nicolas
02:05
created

UrlTransformer::reverseConfiguration()   B

Complexity

Conditions 5
Paths 8

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
ccs 0
cts 0
cp 0
rs 8.8571
cc 5
eloc 10
nc 8
nop 1
crap 30
1
<?php
2
3
namespace Cp\Transformer;
4
5
/**
6
 * Class UrlTransformer
7
 */
8
class UrlTransformer
9
{
10
    /**
11
     * @var string
12
     */
13
    private $baseUrl;
14
15
    /**
16
     * UrlTransformer constructor.
17
     *
18
     * @param string $baseUrl
19
     */
20 1
    public function __construct($baseUrl)
21
    {
22 1
        $this->baseUrl = $baseUrl;
23 1
    }
24
25
    /**
26
     * @param string $week
27
     * @param string $seance
28
     * @param string $type
29
     *
30
     * @return string
31
     */
32 1
    public function transformPlan($week, $seance, $type)
33
    {
34 1
        return sprintf(
35 1
            '%s/plan-entrainement/%s/%s-seances-%s-semaines.html',
36 1
            $this->baseUrl,
37 1
            $type,
38 1
            $seance,
39
            $week
40 1
        );
41
    }
42
43
    /**
44
     * @param string $url
45
     *
46
     * @return array
0 ignored issues
show
Documentation introduced by
Should the return type not be null|array<string,string>?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
47
     */
48
    public function reverseConfiguration($url)
49
    {
50
        $thirdPart = substr($url, strrpos($url, '/') + 1);
51
        preg_match_all('/^([\d]{1,2})-[\w]+-([\d]{1,2})/', $thirdPart, $matches);
52
53
        $seance = isset($matches[1][0]) ? $matches[1][0] : null;
54
        $week = isset($matches[2][0]) ? $matches[2][0] : null;
55
56
        if (null === $seance || null === $week) {
57
            return null;
58
        }
59
60
        return [
61
            'seance' => $seance,
62
            'week' => $week,
63
        ];
64
    }
65
}
66