Skip to content

Commit dd79b22

Browse files
committed
Apply coding standard
1 parent 575fbae commit dd79b22

26 files changed

Lines changed: 963 additions & 1382 deletions

src/Curl/Curl.php

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44

55
namespace Brick\Std\Curl;
66

7+
use function curl_copy_handle;
8+
use function curl_error;
9+
use function curl_exec;
10+
use function curl_getinfo;
11+
use function curl_init;
12+
use function curl_setopt;
13+
use function curl_setopt_array;
14+
use function curl_version;
15+
16+
use const CURLOPT_RETURNTRANSFER;
17+
718
/**
819
* An object wrapper for cURL.
920
*/
@@ -18,30 +29,16 @@ final class Curl
1829

1930
/**
2031
* Class constructor.
21-
*
22-
* @param string|null $url
2332
*/
2433
public function __construct(?string $url = null)
2534
{
2635
$this->curl = ($url === null) ? curl_init() : curl_init($url);
2736
}
2837

2938
/**
30-
* Clone handler.
31-
*
32-
* @return void
33-
*/
34-
public function __clone()
35-
{
36-
$this->curl = curl_copy_handle($this->curl);
37-
}
38-
39-
/**
40-
* @return string
41-
*
4239
* @throws CurlException
4340
*/
44-
public function execute() : string
41+
public function execute(): string
4542
{
4643
// This option must always be set.
4744
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
@@ -62,10 +59,8 @@ public function execute() : string
6259
* Otherwise, an associative array of values is returned.
6360
*
6461
* @param int|null $opt One of the CURLINFO_* constants, or null to return all.
65-
*
66-
* @return mixed
6762
*/
68-
public function getInfo(?int $opt = null)
63+
public function getInfo(?int $opt = null): mixed
6964
{
7065
if ($opt === null) {
7166
return curl_getinfo($this->curl);
@@ -74,32 +69,26 @@ public function getInfo(?int $opt = null)
7469
return curl_getinfo($this->curl, $opt);
7570
}
7671

77-
/**
78-
* @param int $option
79-
* @param mixed $value
80-
*
81-
* @return void
82-
*/
83-
public function setOption(int $option, mixed $value) : void
72+
public function setOption(int $option, mixed $value): void
8473
{
8574
curl_setopt($this->curl, $option, $value);
8675
}
8776

88-
/**
89-
* @param array $options
90-
*
91-
* @return void
92-
*/
93-
public function setOptions(array $options) : void
77+
public function setOptions(array $options): void
9478
{
9579
curl_setopt_array($this->curl, $options);
9680
}
9781

82+
public static function getVersion(): array
83+
{
84+
return curl_version();
85+
}
86+
9887
/**
99-
* @return array
88+
* Clone handler.
10089
*/
101-
public static function getVersion() : array
90+
public function __clone()
10291
{
103-
return curl_version();
92+
$this->curl = curl_copy_handle($this->curl);
10493
}
10594
}

src/Curl/CurlException.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@
44

55
namespace Brick\Std\Curl;
66

7+
use RuntimeException;
8+
9+
use function sprintf;
10+
711
/**
812
* Exception thrown when a Curl request fails.
913
*/
10-
final class CurlException extends \RuntimeException
14+
final class CurlException extends RuntimeException
1115
{
12-
/**
13-
* @param string $error
14-
*
15-
* @return CurlException
16-
*/
17-
public static function error(string $error) : CurlException
16+
public static function error(string $error): CurlException
1817
{
1918
return new self(sprintf('cURL request failed: %s.', $error));
2019
}

src/FixedArray.php

Lines changed: 28 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -4,74 +4,59 @@
44

55
namespace Brick\Std;
66

7+
use ArrayAccess;
8+
use Countable;
9+
use InvalidArgumentException;
10+
use IteratorAggregate;
11+
use SplFixedArray;
12+
use Traversable;
13+
714
/**
815
* An array of fixed length.
916
*
1017
* This class internally wraps SplFixedArray.
1118
*/
12-
final class FixedArray implements \Countable, \IteratorAggregate, \ArrayAccess
19+
final class FixedArray implements Countable, IteratorAggregate, ArrayAccess
1320
{
14-
private \SplFixedArray $splFixedArray;
21+
private SplFixedArray $splFixedArray;
1522

1623
/**
1724
* Class constructor.
18-
*
19-
* @param \SplFixedArray $fixedArray
2025
*/
21-
public function __construct(\SplFixedArray $fixedArray)
26+
public function __construct(SplFixedArray $fixedArray)
2227
{
2328
$this->splFixedArray = $fixedArray;
2429
}
2530

26-
/**
27-
* @param int $size
28-
*
29-
* @return FixedArray
30-
*/
31-
public static function create(int $size = 0) : FixedArray
31+
public static function create(int $size = 0): FixedArray
3232
{
33-
return new FixedArray(new \SplFixedArray($size));
33+
return new FixedArray(new SplFixedArray($size));
3434
}
3535

3636
/**
3737
* Creates a FixedArray from a PHP array.
3838
*
39-
* @param array $array
40-
* @param bool $saveIndexes
41-
*
42-
* @return FixedArray
43-
*
44-
* @throws \InvalidArgumentException If the array contains non-numeric or negative indexes.
39+
* @throws InvalidArgumentException If the array contains non-numeric or negative indexes.
4540
*/
46-
public static function fromArray(array $array, bool $saveIndexes = true) : FixedArray
41+
public static function fromArray(array $array, bool $saveIndexes = true): FixedArray
4742
{
48-
return new FixedArray(\SplFixedArray::fromArray($array, $saveIndexes));
43+
return new FixedArray(SplFixedArray::fromArray($array, $saveIndexes));
4944
}
5045

51-
/**
52-
* @return array
53-
*/
54-
public function toArray() : array
46+
public function toArray(): array
5547
{
5648
return $this->splFixedArray->toArray();
5749
}
5850

5951
/**
6052
* Returns the size of the array.
61-
*
62-
* @return int
6353
*/
64-
public function getSize() : int
54+
public function getSize(): int
6555
{
6656
return $this->splFixedArray->getSize();
6757
}
6858

69-
/**
70-
* @param int $size
71-
*
72-
* @return void
73-
*/
74-
public function setSize(int $size) : void
59+
public function setSize(int $size): void
7560
{
7661
$this->splFixedArray->setSize($size);
7762
}
@@ -80,10 +65,8 @@ public function setSize(int $size) : void
8065
* Returns the size of the array.
8166
*
8267
* This is an alias of getSize(), required by interface Countable.
83-
*
84-
* @return int
8568
*/
86-
public function count() : int
69+
public function count(): int
8770
{
8871
return $this->splFixedArray->count();
8972
}
@@ -94,10 +77,8 @@ public function count() : int
9477
* Required by interface ArrayAccess.
9578
*
9679
* @param int $offset
97-
*
98-
* @return bool
9980
*/
100-
public function offsetExists(mixed $offset) : bool
81+
public function offsetExists(mixed $offset): bool
10182
{
10283
return $this->splFixedArray->offsetExists($offset);
10384
}
@@ -108,8 +89,6 @@ public function offsetExists(mixed $offset) : bool
10889
* Required by interface ArrayAccess.
10990
*
11091
* @param int $offset
111-
*
112-
* @return mixed
11392
*/
11493
public function offsetGet(mixed $offset): mixed
11594
{
@@ -121,12 +100,9 @@ public function offsetGet(mixed $offset): mixed
121100
*
122101
* Required by interface ArrayAccess.
123102
*
124-
* @param int $offset
125-
* @param mixed $value
126-
*
127-
* @return void
103+
* @param int $offset
128104
*/
129-
public function offsetSet(mixed $offset, mixed $value) : void
105+
public function offsetSet(mixed $offset, mixed $value): void
130106
{
131107
$this->splFixedArray->offsetSet($offset, $value);
132108
}
@@ -137,10 +113,8 @@ public function offsetSet(mixed $offset, mixed $value) : void
137113
* Required by interface ArrayAccess.
138114
*
139115
* @param int $offset
140-
*
141-
* @return void
142116
*/
143-
public function offsetUnset(mixed $offset) : void
117+
public function offsetUnset(mixed $offset): void
144118
{
145119
$this->splFixedArray->offsetUnset($offset);
146120
}
@@ -149,10 +123,8 @@ public function offsetUnset(mixed $offset) : void
149123
* Returns an iterator for this fixed array.
150124
*
151125
* Required by interface IteratorAggregate.
152-
*
153-
* @return \Traversable
154126
*/
155-
public function getIterator() : \Traversable
127+
public function getIterator(): Traversable
156128
{
157129
return $this->splFixedArray;
158130
}
@@ -162,10 +134,8 @@ public function getIterator() : \Traversable
162134
*
163135
* @param int $index1 The index of the first entry.
164136
* @param int $index2 The index of the second entry.
165-
*
166-
* @return void
167137
*/
168-
public function swap(int $index1, int $index2) : void
138+
public function swap(int $index1, int $index2): void
169139
{
170140
if ($index1 !== $index2) {
171141
$value = $this[$index1];
@@ -179,12 +149,8 @@ public function swap(int $index1, int $index2) : void
179149
*
180150
* This will effectively swap this entry with the next entry.
181151
* If this entry is the last one in the array, this method will do nothing.
182-
*
183-
* @param int $index
184-
*
185-
* @return void
186152
*/
187-
public function shiftUp(int $index) : void
153+
public function shiftUp(int $index): void
188154
{
189155
if ($index + 1 === $this->count()) {
190156
return;
@@ -198,12 +164,8 @@ public function shiftUp(int $index) : void
198164
*
199165
* This will effectively swap this entry with the previous entry.
200166
* If the entry is the first one in the array, this method will do nothing.
201-
*
202-
* @param int $index
203-
*
204-
* @return void
205167
*/
206-
public function shiftDown(int $index) : void
168+
public function shiftDown(int $index): void
207169
{
208170
if ($index === 0) {
209171
return;
@@ -217,10 +179,8 @@ public function shiftDown(int $index) : void
217179
*
218180
* @param int $index The index of the entry.
219181
* @param int $newIndex The index to shift the entry to.
220-
*
221-
* @return void
222182
*/
223-
public function shiftTo(int $index, int $newIndex) : void
183+
public function shiftTo(int $index, int $newIndex): void
224184
{
225185
while ($index > $newIndex) {
226186
$this->shiftDown($index);

src/Internal/ErrorCatcher.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
namespace Brick\Std\Internal;
66

7+
use ErrorException;
8+
9+
use function restore_error_handler;
10+
use function set_error_handler;
11+
712
/**
813
* Catches PHP errors in a specific code block, and throws exceptions.
914
*
@@ -20,12 +25,12 @@ final class ErrorCatcher
2025
*
2126
* @return mixed The return value of the function.
2227
*
23-
* @throws \ErrorException If a PHP error occurs.
28+
* @throws ErrorException If a PHP error occurs.
2429
*/
25-
public static function run(callable $function)
30+
public static function run(callable $function): mixed
2631
{
27-
set_error_handler(static function($severity, $message, $file, $line) {
28-
throw new \ErrorException($message, 0, $severity, $file, $line);
32+
set_error_handler(static function ($severity, $message, $file, $line): void {
33+
throw new ErrorException($message, 0, $severity, $file, $line);
2934
});
3035

3136
try {

0 commit comments

Comments
 (0)