CFilms   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 79
Duplicated Lines 20.25 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 16
loc 79
ccs 32
cts 32
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A program() 0 22 2
A filmInfo() 0 13 1
A getProg() 8 8 1
A getFilm() 8 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace rolb\CFilm;
4
5
class CFilms
6
{
7
    private $apikey;
8
    private $date;
9
10
11
12
    /**
13
     * CFilms constructor.
14
     * @param $apikey
15
     * @param $date
16
     */
17 4
    public function __construct($apikey, $date)
18
    {
19 4
        $this->apikey = $apikey;
20 4
        $this->date = $date;
21 4
    }
22
23
24
    /**
25
     * Renders the html
26
     */
27 1
    public function program()
28
    {
29 1
        $data = $this->getProg();
30
31 1
        $html = '<div class="date"> Stockholms Filmfestival Programme ' . $this->date . '<br></div>';
32
33 1
        foreach($data as $value) {
34
35 1
            $filmid = $value["filmId"];
36
37 1
            $html .= '<br><div class="ftime">' . substr(htmlentities($value["eventTime"]), 0, -3) . '</div>';
38
39 1
            $html .= '<div class="fname"><a href="sthlmfilms?film=' . $filmid . '">' . htmlentities($value["eventName_en"]) . '</a></div>';
40
41 1
            $html .= '<div class="fvenue">Venue: ' . htmlentities($value["venueName"]) . '</div>';
42
43 1
            $html .= '<br>';
44
45 1
        }
46
47 1
        return $html;
48
    }
49
50 1
    public function filmInfo($filmid)
51
    {
52 1
        $filmdata = $this->getFilm($filmid);
53
54 1
        $html = '';
55 1
        $html .= '<br><div class="ftitle">' . htmlentities($filmdata["filmName"]) . '</div>';
56 1
        $html .= '<br><div class="fdir"> Director: ' . htmlentities($filmdata["filmDirector"]) . '</div>';
57 1
        $html .= '<br><div class="flength">' . htmlentities($filmdata["filmLength"]) . ' minutes </div>';
58 1
        $html .= '<br><div class="finfo">' . htmlentities($filmdata["filmDescription_en"]) . '</div>';
59 1
        $html .= '<br><div class="flink"> <iframe width="420" height="315"src="https://www.youtube.com/embed/' . htmlentities($filmdata["filmYoutubeId"]) . '"></iframe></div>';
60
61 1
        return $html;
62
    }
63
64 2 View Code Duplication
    private function getProg()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
65
    {
66
67 2
        $result = file_get_contents("http://api.stockholmfilmfestival.se/v1/events/date_list/format/json/date/"
68 2
            . $this->date . "/API-Key/" . $this->apikey);
69
70 2
        return json_decode($result, true);
71
    }
72
73
74 2 View Code Duplication
    private function getFilm($filmid)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
    {
76
77 2
        $result = file_get_contents("http://api.stockholmfilmfestival.se/v1/films/film/film_id/"
78 2
            . $filmid . "/API-Key/" . $this->apikey . "/format/json/");
79
80 2
        return json_decode($result, true);
81
    }
82
83
}