Skip to content

Commit 7f92b07

Browse files
committed
Add new php-cs-fixer rules
1 parent 973938f commit 7f92b07

File tree

16 files changed

+63
-35
lines changed

16 files changed

+63
-35
lines changed

.php_cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,20 @@ return PhpCsFixer\Config::create()
55
->setRules([
66
'@Symfony' => true,
77
'@Symfony:risky' => true,
8+
'@PhpCsFixer' => true,
9+
'@PSR1' => true,
10+
'@PSR2' => true,
11+
'@PSR12' => true,
12+
'@PSR12:risky' => true,
813
'array_syntax' => ['syntax' => 'short'],
914
'combine_consecutive_unsets' => true,
1015
'concat_space' => [ 'spacing' => 'one'],
16+
'explicit_string_variable' => false,
17+
'fopen_flags' => ['b_mode' => true],
1118
'heredoc_to_nowdoc' => true,
1219
'increment_style' => false,
13-
'list_syntax' => ['syntax' => 'long'],
20+
'list_syntax' => ['syntax' => 'short'],
21+
'multiline_whitespace_before_semicolons' => false,
1422
'no_extra_consecutive_blank_lines' => ['break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block'],
1523
'no_short_echo_tag' => true,
1624
'no_unreachable_default_argument_value' => true,
@@ -23,6 +31,7 @@ return PhpCsFixer\Config::create()
2331
'phpdoc_add_missing_param_annotation' => true,
2432
'phpdoc_no_alias_tag' => false,
2533
'phpdoc_order' => true,
34+
'phpdoc_types_order' => ['sort_algorithm' => 'alpha', 'null_adjustment' => 'always_last'],
2635
'semicolon_after_instruction' => true,
2736
'single_line_throw' => false,
2837
'strict_comparison' => true,
@@ -31,6 +40,7 @@ return PhpCsFixer\Config::create()
3140
])
3241
->setFinder(
3342
PhpCsFixer\Finder::create()
43+
->exclude('ext')
3444
->in(__DIR__)
3545
)
3646
;

bin/benchmark.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
$reader = new Reader('GeoLite2-City.mmdb');
1111
$count = 40000;
1212
$startTime = microtime(true);
13-
for ($i = 0; $i < $count; $i++) {
13+
for ($i = 0; $i < $count; ++$i) {
1414
$ip = long2ip(rand(0, 2 ** 32 - 1));
15+
1516
try {
1617
$t = $reader->city($ip);
1718
} catch (AddressNotFoundException $e) {

dev-bin/phar-test.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@
1212
}
1313

1414
echo 'Problem with Phar!';
15+
1516
exit(1);

examples/benchmark.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
$startTime = microtime(true);
1212
for ($i = 0; $i < $count; ++$i) {
1313
$ip = long2ip(rand(0, 2 ** 32 - 1));
14+
1415
try {
1516
$t = $reader->city($ip);
1617
} catch (\GeoIp2\Exception\AddressNotFoundException $e) {

src/Database/Reader.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public function isp(string $ipAddress): \GeoIp2\Model\Isp
218218

219219
private function modelFor(string $class, string $type, string $ipAddress): AbstractModel
220220
{
221-
list($record, $prefixLen) = $this->getRecord($class, $type, $ipAddress);
221+
[$record, $prefixLen] = $this->getRecord($class, $type, $ipAddress);
222222

223223
$record['traits']['ip_address'] = $ipAddress;
224224
$record['traits']['prefix_len'] = $prefixLen;
@@ -230,7 +230,7 @@ private function modelFor(string $class, string $type, string $ipAddress): Abstr
230230

231231
private function flatModelFor(string $class, string $type, string $ipAddress): AbstractModel
232232
{
233-
list($record, $prefixLen) = $this->getRecord($class, $type, $ipAddress);
233+
[$record, $prefixLen] = $this->getRecord($class, $type, $ipAddress);
234234

235235
$record['ip_address'] = $ipAddress;
236236
$record['prefix_len'] = $prefixLen;
@@ -243,11 +243,12 @@ private function getRecord(string $class, string $type, string $ipAddress): arra
243243
{
244244
if (strpos($this->dbType, $type) === false) {
245245
$method = lcfirst($class);
246+
246247
throw new \BadMethodCallException(
247248
"The $method method cannot be used to open a {$this->dbType} database"
248249
);
249250
}
250-
list($record, $prefixLen) = $this->dbReader->getWithPrefixLen($ipAddress);
251+
[$record, $prefixLen] = $this->dbReader->getWithPrefixLen($ipAddress);
251252
if ($record === null) {
252253
throw new AddressNotFoundException(
253254
"The address $ipAddress is not in the database."

src/Model/AbstractModel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ protected function get(string $field)
4747
public function __get(string $attr)
4848
{
4949
if ($attr !== 'instance' && property_exists($this, $attr)) {
50-
return $this->$attr;
50+
return $this->{$attr};
5151
}
5252

5353
throw new \RuntimeException("Unknown attribute: $attr");
@@ -58,7 +58,7 @@ public function __get(string $attr)
5858
*/
5959
public function __isset(string $attr): bool
6060
{
61-
return $attr !== 'instance' && isset($this->$attr);
61+
return $attr !== 'instance' && isset($this->{$attr});
6262
}
6363

6464
public function jsonSerialize(): array

src/Model/City.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private function createSubdivisions(array $raw, array $locales): void
9191
public function __get(string $attr)
9292
{
9393
if ($attr === 'mostSpecificSubdivision') {
94-
return $this->$attr();
94+
return $this->{$attr}();
9595
}
9696

9797
return parent::__get($attr);

src/Record/AbstractRecord.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,22 @@ public function __get(string $attr)
3131

3232
if ($this->__isset($attr)) {
3333
return $this->record[$key];
34-
} elseif ($this->validAttribute($attr)) {
34+
}
35+
if ($this->validAttribute($attr)) {
3536
if (preg_match('/^is_/', $key)) {
3637
return false;
3738
}
3839

3940
return null;
4041
}
42+
4143
throw new \RuntimeException("Unknown attribute: $attr");
4244
}
4345

4446
public function __isset(string $attr): bool
4547
{
46-
return $this->validAttribute($attr) &&
47-
isset($this->record[$this->attributeToKey($attr)]);
48+
return $this->validAttribute($attr)
49+
&& isset($this->record[$this->attributeToKey($attr)]);
4850
}
4951

5052
private function attributeToKey(string $attr): string

src/Record/Traits.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class Traits extends AbstractRecord
139139

140140
public function __construct(?array $record)
141141
{
142-
if (!isset($record['network']) && isset($record['ip_address']) && isset($record['prefix_len'])) {
142+
if (!isset($record['network']) && isset($record['ip_address'], $record['prefix_len'])) {
143143
$record['network'] = Util::cidr($record['ip_address'], $record['prefix_len']);
144144
}
145145

src/WebService/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Client implements ProviderInterface
6161
*/
6262
private static $basePath = '/geoip/v2.1';
6363

64-
const VERSION = 'v2.11.0';
64+
public const VERSION = 'v2.11.0';
6565

6666
/**
6767
* Constructor.

0 commit comments

Comments
 (0)