UrlTransformer   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 8
c 2
b 0
f 0
lcom 1
cbo 0
dl 0
loc 68
rs 10
ccs 22
cts 22
cp 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A transformPlan() 0 10 1
A transformType() 0 4 1
B reverseConfiguration() 0 17 5
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 3
    public function __construct($baseUrl)
21
    {
22 3
        $this->baseUrl = $baseUrl;
23 3
    }
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 $typeName
45
     *
46
     * @return string
47
     */
48 1
    public function transformType($typeName)
49
    {
50 1
        return sprintf('%s/plan-entrainement/%s.html', $this->baseUrl, $typeName);
51
    }
52
53
    /**
54
     * @param string $url
55
     *
56
     * @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...
57
     */
58 1
    public function reverseConfiguration($url)
59
    {
60 1
        $thirdPart = substr($url, strrpos($url, '/') + 1);
61 1
        preg_match_all('/^([\d]{1,2})-[\w]+-([\d]{1,2})/', $thirdPart, $matches);
62
63 1
        $seance = isset($matches[1][0]) ? $matches[1][0] : null;
64 1
        $week = isset($matches[2][0]) ? $matches[2][0] : null;
65
66 1
        if (null === $seance || null === $week) {
67 1
            return null;
68
        }
69
70
        return [
71 1
            'seance' => $seance,
72 1
            'week' => $week,
73 1
        ];
74
    }
75
}
76