Completed
Push — master ( 2430a5...3c523b )
by Joschi
03:35
created

Psr7Trait::getAuthority()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
1
<?php
2
3
/**
4
 * apparat-object
5
 *
6
 * @category    Apparat
7
 * @package     Apparat\Object
8
 * @subpackage  Apparat\Object\Domain
9
 * @author      Joschi Kuphal <[email protected]> / @jkphl
10
 * @copyright   Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl
11
 * @license     http://opensource.org/licenses/MIT The MIT License (MIT)
12
 */
13
14
/***********************************************************************************
15
 *  The MIT License (MIT)
16
 *
17
 *  Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl
18
 *
19
 *  Permission is hereby granted, free of charge, to any person obtaining a copy of
20
 *  this software and associated documentation files (the "Software"), to deal in
21
 *  the Software without restriction, including without limitation the rights to
22
 *  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
23
 *  the Software, and to permit persons to whom the Software is furnished to do so,
24
 *  subject to the following conditions:
25
 *
26
 *  The above copyright notice and this permission notice shall be included in all
27
 *  copies or substantial portions of the Software.
28
 *
29
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
31
 *  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
32
 *  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
33
 *  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34
 *  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
 ***********************************************************************************/
36
37
namespace Apparat\Object\Domain\Model\Path\Traits;
38
39
use Apparat\Object\Domain\Model\Path\Url;
40
41
/**
42
 * PSR-7 URI trait
43
 *
44
 * @package Apparat\Object\Domain\Model\Path\Traits
45
 * @method Url setUser()
46
 */
47
trait Psr7Trait
48
{
49
    /**
50
     * Return the URL path
51
     *
52
     * @return string URL path
53
     */
54 34
    public function getPath()
55
    {
56 34
        return $this->urlParts['path'];
0 ignored issues
show
Bug introduced by
The property urlParts does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
57
    }
58
59
    /**
60
     * Return the URL host
61
     *
62
     * @return string URL host
63
     */
64 31
    public function getHost()
65
    {
66 31
        return isset($this->urlParts['host']) ? $this->urlParts['host'] : null;
67
    }
68
69
    /**
70
     * Return the URL port
71
     *
72
     * @return int URL port
73
     */
74 11
    public function getPort()
75
    {
76 11
        return isset($this->urlParts['port']) ? $this->urlParts['port'] : null;
77
    }
78
79
    /**
80
     * Return the URL fragment
81
     *
82
     * @return string URL fragment
83
     */
84 11
    public function getFragment()
85
    {
86 11
        return isset($this->urlParts['fragment']) ? $this->urlParts['fragment'] : null;
87
    }
88
89
    /**
90
     * Return the URL query
91
     *
92
     * @return array URL query
93
     */
94 7
    public function getQuery()
95
    {
96 7
        return isset($this->urlParts['query']) ? $this->urlParts['query'] : '';
97
    }
98
99
    /**
100
     * Return the URL scheme
101
     *
102
     * @return string URL scheme
103
     */
104 31
    public function getScheme()
105
    {
106 31
        return isset($this->urlParts['scheme']) ? $this->urlParts['scheme'] : null;
107
    }
108
109
    /**
110
     * Return the URL authority
111
     *
112
     * @return string
113
     */
114 1
    public function getAuthority()
115
    {
116 1
        $uriParts = [];
117 1
        $this->getUrlInternal($uriParts);
0 ignored issues
show
Bug introduced by
It seems like getUrlInternal() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
118 1
        return $uriParts['user'].$uriParts['pass'].$uriParts['host'].$uriParts['port'];
119
    }
120
121
    /**
122
     * Return the URL user info
123
     *
124
     * @return string
125
     */
126 1
    public function getUserInfo()
127
    {
128 1
        $uriParts = [];
129 1
        $this->getUrlInternal($uriParts);
0 ignored issues
show
Bug introduced by
It seems like getUrlInternal() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
130 1
        return rtrim($uriParts['user'].$uriParts['pass'], '@');
131
    }
132
133
    /**
134
     * Return an instance of this URL with the given scheme
135
     *
136
     * @param string $scheme Scheme
137
     * @return Url Instance with the given scheme
138
     */
139 1
    public function withScheme($scheme)
140
    {
141 1
        return $this->setScheme($scheme);
0 ignored issues
show
Bug introduced by
It seems like setScheme() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
142
    }
143
144
    /**
145
     * Return an instance of this URL with the given user info
146
     *
147
     * @param string $user User name
148
     * @param string|null $password Password
149
     * @return Url URL instance with given user info
150
     */
151 1
    public function withUserInfo($user, $password = null)
152
    {
153 1
        return $this->setUser($user)->setPassword($password);
0 ignored issues
show
Unused Code introduced by
The call to Psr7Trait::setUser() has too many arguments starting with $user.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
154
    }
155
156
    /**
157
     * Return an instance of this URL with the given host
158
     *
159
     * @param string $host Host
160
     * @return Url Instance with the given host
161
     */
162 1
    public function withHost($host)
163
    {
164 1
        return $this->setHost($host);
0 ignored issues
show
Bug introduced by
It seems like setHost() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
165
    }
166
167
    /**
168
     * Return an instance of this URL with the given port
169
     *
170
     * @param null|int $port Port
171
     * @return Url Instance with the given port
172
     */
173 1
    public function withPort($port)
174
    {
175 1
        return $this->setPort($port);
0 ignored issues
show
Bug introduced by
It seems like setPort() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
176
    }
177
178
    /**
179
     * Return an instance of this URL with the given path
180
     *
181
     * @param null|int $path Path
182
     * @return Url Instance with the given path
183
     */
184 1
    public function withPath($path)
185
    {
186 1
        return $this->setPath($path);
0 ignored issues
show
Bug introduced by
It seems like setPath() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
187
    }
188
189
    /**
190
     * Return an instance of this URL with the given query
191
     *
192
     * @param null|string $query Query
193
     * @return Url Instance with the given query
194
     */
195 1
    public function withQuery($query)
196
    {
197 1
        return $this->setQuery($query);
0 ignored issues
show
Bug introduced by
It seems like setQuery() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
198
    }
199
200
    /**
201
     * Return an instance of this URL with the given fragment
202
     *
203
     * @param null|int $fragment Fragment
204
     * @return Url Instance with the given fragment
205
     */
206 1
    public function withFragment($fragment)
207
    {
208 1
        return $this->setFragment($fragment);
0 ignored issues
show
Bug introduced by
It seems like setFragment() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
209
    }
210
}