HttpJsonApi   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 40
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A getDescription() 0 4 1
A getRequests() 0 10 1
A getType() 0 4 1
1
<?php
2
3
namespace PhpSchool\LearnYouPhp\Exercise;
4
5
use PhpSchool\PhpWorkshop\Exercise\AbstractExercise;
6
use PhpSchool\PhpWorkshop\Exercise\CgiExercise;
7
use PhpSchool\PhpWorkshop\Exercise\ExerciseInterface;
8
use PhpSchool\PhpWorkshop\Exercise\ExerciseType;
9
use PhpSchool\PhpWorkshop\ExerciseCheck\CgiOutputExerciseCheck;
10
use Psr\Http\Message\RequestInterface;
11
use Zend\Diactoros\Request;
12
13
/**
14
 * Class HttpJsonApi
15
 * @package PhpSchool\LearnYouPhp\Exercise
16
 * @author Aydin Hassan <[email protected]>
17
 */
18
class HttpJsonApi extends AbstractExercise implements ExerciseInterface, CgiExercise
19
{
20
    /**
21
     * @return string
22
     */
23
    public function getName()
24
    {
25
        return 'HTTP JSON API';
26
    }
27
28
    /**
29
     * @return string
30
     */
31
    public function getDescription()
32
    {
33
        return 'HTTP JSON API - Servers JSON when it receives a GET request';
34
    }
35
    
36
    /**
37
     * @return RequestInterface[]
38
     */
39
    public function getRequests()
40
    {
41
        $url = 'http://www.time.com/api/%s?iso=%s';
42
        return [
43
            (new Request(sprintf($url, 'parsetime', urlencode((new \DateTime)->format(DATE_ISO8601)))))
44
                ->withMethod('GET'),
45
            (new Request(sprintf($url, 'unixtime', urlencode((new \DateTime)->format(DATE_ISO8601)))))
46
                ->withMethod('GET'),
47
        ];
48
    }
49
50
    /**
51
     * @return ExerciseType
52
     */
53
    public function getType()
54
    {
55
        return ExerciseType::CGI();
56
    }
57
}
58