Completed
Push — master ( 007be0...4b2a2e )
by Ricardo
10s
created

AbstractServiceAdapter::setRenderer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Ricardo Fiorani
5
 * Date: 29/08/2015
6
 * Time: 19:37.
7
 */
8
namespace RicardoFiorani\Adapter;
9
10
use RicardoFiorani\Exception\NotEmbeddableException;
11
use RicardoFiorani\Renderer\EmbedRendererInterface;
12
13
abstract class AbstractServiceAdapter implements VideoAdapterInterface
14
{
15
    /**
16
     * @var string
17
     */
18
    public $rawUrl;
19
20
    /**
21
     * @var string
22
     */
23
    public $videoId;
24
25
    /**
26
     * @var string
27
     */
28
    public $pattern;
29
30
    /**
31
     * @var EmbedRendererInterface
32
     */
33
    public $renderer;
34
35
    /**
36
     * AbstractVideoAdapter constructor.
37
     *
38
     * @param string $url
39
     * @param string $pattern
40
     * @param EmbedRendererInterface $renderer
41
     */
42 51
    public function __construct($url, $pattern, EmbedRendererInterface $renderer)
43
    {
44 51
        $this->rawUrl = $url;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
45 51
        $this->pattern = $pattern;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
46 51
        $this->renderer = $renderer;
47 51
    }
48
49
    /**
50
     * Returns the input URL.
51
     *
52
     * @return string
53
     */
54 2
    public function getRawUrl()
55
    {
56 2
        return $this->rawUrl;
57
    }
58
59
    /**
60
     * @param string $rawUrl
61
     */
62 1
    public function setRawUrl($rawUrl)
63
    {
64 1
        $this->rawUrl = $rawUrl;
65 1
    }
66
67
    /**
68
     * @return string
69
     */
70 17
    public function getVideoId()
71
    {
72 17
        return $this->videoId;
73
    }
74
75
    /**
76
     * @param string $videoId
77
     */
78 51
    public function setVideoId($videoId)
79
    {
80 51
        $this->videoId = $videoId;
81 51
    }
82
83
    /**
84
     * @return string
85
     */
86 2
    public function getPattern()
87
    {
88 2
        return $this->pattern;
89
    }
90
91
    /**
92
     * @param string $pattern
93
     */
94 1
    public function setPattern($pattern)
95
    {
96 1
        $this->pattern = $pattern;
97 1
    }
98
99
    /**
100
     * @return EmbedRendererInterface
101
     */
102 2
    public function getRenderer()
103
    {
104 2
        return $this->renderer;
105
    }
106
107
    /**
108
     * @param EmbedRendererInterface $renderer
109
     */
110 1
    public function setRenderer($renderer)
111
    {
112 1
        $this->renderer = $renderer;
113 1
    }
114
115
    /**
116
     * @param int $width
117
     * @param int $height
118
     * @param bool $autoplay
119
     *
120
     * @return string
121
     *
122
     * @throws NotEmbeddableException
123
     */
124 1
    public function getEmbedCode($width, $height, $autoplay = false, $secure = false)
125
    {
126 1
        if (false == $this->isEmbeddable()) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
127
            throw new NotEmbeddableException();
128
        }
129
130 1
        return $this->getRenderer()->renderVideoEmbedCode($this->getEmbedUrl($autoplay, $secure), $width, $height);
131
    }
132
133
    /**
134
     * Switches the protocol scheme between http and https
135
     *
136
     * @param bool|false $secure
137
     * @return string
138
     */
139
    public function getScheme($secure = false)
140
    {
141
        return ($secure ? 'https' : 'http');
142
    }
143
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
144