Completed
Push — master ( 415647...d02380 )
by Ricardo
02:50
created

AbstractServiceAdapter::getScheme()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 7
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 6
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
    public function __construct($url, $pattern, EmbedRendererInterface $renderer)
43
    {
44
        $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
        $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
        $this->renderer = $renderer;
47
    }
48
49
    /**
50
     * Returns the input URL.
51
     *
52
     * @return string
53
     */
54
    public function getRawUrl()
55
    {
56
        return $this->rawUrl;
57
    }
58
59
    /**
60
     * @param string $rawUrl
61
     */
62
    public function setRawUrl($rawUrl)
63
    {
64
        $this->rawUrl = $rawUrl;
65
    }
66
67
    /**
68
     * @return string
69
     */
70
    public function getVideoId()
71
    {
72
        return $this->videoId;
73
    }
74
75
    /**
76
     * @param string $videoId
77
     */
78
    public function setVideoId($videoId)
79
    {
80
        $this->videoId = $videoId;
81
    }
82
83
    /**
84
     * @return string
85
     */
86
    public function getPattern()
87
    {
88
        return $this->pattern;
89
    }
90
91
    /**
92
     * @param string $pattern
93
     */
94
    public function setPattern($pattern)
95
    {
96
        $this->pattern = $pattern;
97
    }
98
99
    /**
100
     * @return EmbedRendererInterface
101
     */
102
    public function getRenderer()
103
    {
104
        return $this->renderer;
105
    }
106
107
    /**
108
     * @param EmbedRendererInterface $renderer
109
     */
110
    public function setRenderer($renderer)
111
    {
112
        $this->renderer = $renderer;
113
    }
114
115
    /**
116
     * @param int $width
117
     * @param int $height
118
     * @param bool $forceAutoplay
119
     * @param bool $forceSecure
120
     *
121
     * @return string
122
     * @throws NotEmbeddableException
123
     */
124
    public function getEmbedCode($width, $height, $forceAutoplay = false, $forceSecure = false)
125
    {
126
        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
        return $this->getRenderer()->renderVideoEmbedCode(
131
            $this->getEmbedUrl($forceAutoplay, $forceSecure),
132
            $width,
133
            $height
134
        );
135
    }
136
137
    /**
138
     * Switches the protocol scheme between http and https in case you want to force https
139
     *
140
     * @param bool|false $forceSecure
141
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be string|false?

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...
142
     */
143
    public function getScheme($forceSecure = false)
144
    {
145
        if ($forceSecure) {
146
            return 'https';
147
        }
148
149
        return parse_url($this->rawUrl, PHP_URL_SCHEME);
150
    }
151
}
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...
152