Skip to content

Commit bfe60b6

Browse files
committed
Add Rector and apply changes from it
1 parent e313d23 commit bfe60b6

23 files changed

+206
-231
lines changed

composer.json

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"orchestra/testbench": "^8.8 || ^9.0",
2525
"phpstan/phpstan": "^1.10",
2626
"phpunit/phpunit": "^10.5 || ^11.0",
27+
"rector/rector": "^1.2",
2728
"squizlabs/php_codesniffer": "^3.9",
2829
"vimeo/psalm": "^5.25"
2930
},
@@ -63,6 +64,7 @@
6364
"phpcs": "vendor/bin/phpcs --standard=phpcs.xml src",
6465
"phpstan": "vendor/bin/phpstan --level=0 --no-progress analyse --configuration phpstan.neon --memory-limit 2G",
6566
"psalm": "vendor/bin/psalm",
67+
"rector": "vendor/bin/rector process --config rector.php ",
6668
"sa": "@psalm",
6769
"sa:bl": "@psalm --set-baseline=psalm-baseline.xml",
6870
"test": "vendor/bin/phpunit"

psalm-baseline.xml

+39-53
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<files psalm-version="5.25.0@01a8eb06b9e9cc6cfb6a320bf9fb14331919d505">
2+
<files psalm-version="5.26.1@d747f6500b38ac4f7dfc5edbcae6e4b637d7add0">
33
<file src="src/Cache.php">
44
<MixedInferredReturnType>
55
<code><![CDATA[bool]]></code>
66
</MixedInferredReturnType>
77
<MixedReturnStatement>
88
<code><![CDATA[$this->cache->flush()]]></code>
9+
<code><![CDATA[$this->cache->flush()]]></code>
910
</MixedReturnStatement>
10-
<PossiblyInvalidPropertyAssignmentValue>
11-
<code><![CDATA[($tags === [] || !$cache->supportsTags()) ? $cache : $cache->tags($tags)]]></code>
12-
</PossiblyInvalidPropertyAssignmentValue>
1311
</file>
1412
<file src="src/Console/Clear.php">
15-
<DeprecatedMethod>
16-
<code><![CDATA[fire]]></code>
17-
</DeprecatedMethod>
18-
<InvalidReturnStatement>
19-
<code><![CDATA[$this->output->error('Default cache system does not support tags')]]></code>
20-
</InvalidReturnStatement>
2113
<MixedMethodCall>
2214
<code><![CDATA[config]]></code>
2315
<code><![CDATA[flush]]></code>
@@ -34,20 +26,24 @@
3426
</PropertyNotSetInConstructor>
3527
</file>
3628
<file src="src/Console/Update.php">
37-
<DeprecatedMethod>
38-
<code><![CDATA[fire]]></code>
39-
</DeprecatedMethod>
4029
<MixedArgument>
4130
<code><![CDATA[$result]]></code>
42-
<code><![CDATA[$service]]></code>
43-
<code><![CDATA[$service]]></code>
4431
</MixedArgument>
4532
<MixedAssignment>
4633
<code><![CDATA[$result]]></code>
4734
</MixedAssignment>
35+
<MixedInferredReturnType>
36+
<code><![CDATA[int]]></code>
37+
</MixedInferredReturnType>
4838
<MixedMethodCall>
4939
<code><![CDATA[getService]]></code>
5040
</MixedMethodCall>
41+
<MixedReturnStatement>
42+
<code><![CDATA[static::FAILURE]]></code>
43+
<code><![CDATA[static::FAILURE]]></code>
44+
<code><![CDATA[static::SUCCESS]]></code>
45+
<code><![CDATA[static::SUCCESS]]></code>
46+
</MixedReturnStatement>
5147
<NonInvariantDocblockPropertyType>
5248
<code><![CDATA[$description]]></code>
5349
</NonInvariantDocblockPropertyType>
@@ -76,22 +72,8 @@
7672
<code><![CDATA[$this->remote_ip]]></code>
7773
</DeprecatedProperty>
7874
<DocblockTypeContradiction>
79-
<code><![CDATA[$this->currencies === null]]></code>
8075
<code><![CDATA[$this->service === null]]></code>
8176
</DocblockTypeContradiction>
82-
<InvalidPropertyAssignmentValue>
83-
<code><![CDATA[new Cache(
84-
$cache,
85-
$this->config('cache_tags'),
86-
$this->config('cache_expires', 30)
87-
)]]></code>
88-
</InvalidPropertyAssignmentValue>
89-
<InvalidReturnStatement>
90-
<code><![CDATA[$this->cache]]></code>
91-
</InvalidReturnStatement>
92-
<InvalidReturnType>
93-
<code><![CDATA[\InteractionDesignFoundation\GeoIP\Cache]]></code>
94-
</InvalidReturnType>
9577
<LessSpecificReturnStatement>
9678
<code><![CDATA[$this->service]]></code>
9779
</LessSpecificReturnStatement>
@@ -109,7 +91,7 @@
10991
<code><![CDATA[$config]]></code>
11092
</MixedAssignment>
11193
<MixedInferredReturnType>
112-
<code><![CDATA[string]]></code>
94+
<code><![CDATA[string|null]]></code>
11395
</MixedInferredReturnType>
11496
<MixedMethodCall>
11597
<code><![CDATA[new $class($config)]]></code>
@@ -126,11 +108,8 @@
126108
<PossiblyNullArgument>
127109
<code><![CDATA[$ip]]></code>
128110
<code><![CDATA[$location->iso_code]]></code>
111+
<code><![CDATA[$this->currencies]]></code>
129112
</PossiblyNullArgument>
130-
<PossiblyNullPropertyAssignmentValue>
131-
<code><![CDATA[null]]></code>
132-
<code><![CDATA[null]]></code>
133-
</PossiblyNullPropertyAssignmentValue>
134113
<PropertyNotSetInConstructor>
135114
<code><![CDATA[$service]]></code>
136115
</PropertyNotSetInConstructor>
@@ -144,22 +123,17 @@
144123
</RiskyTruthyFalsyComparison>
145124
</file>
146125
<file src="src/GeoIPServiceProvider.php">
147-
<MissingClosureParamType>
148-
<code><![CDATA[$app]]></code>
149-
</MissingClosureParamType>
150126
<MixedArgument>
151-
<code><![CDATA[$app->config->get('geoip', [])]]></code>
152127
<code><![CDATA[$app['cache']]]></code>
128+
<code><![CDATA[$app['config']->get('geoip', [])]]></code>
153129
</MixedArgument>
154-
<MixedArrayAccess>
155-
<code><![CDATA[$app['cache']]]></code>
156-
</MixedArrayAccess>
157130
<MixedMethodCall>
158131
<code><![CDATA[get]]></code>
159132
</MixedMethodCall>
160-
<MixedPropertyFetch>
161-
<code><![CDATA[$app->config]]></code>
162-
</MixedPropertyFetch>
133+
<UndefinedInterfaceMethod>
134+
<code><![CDATA[$app]]></code>
135+
<code><![CDATA[$app]]></code>
136+
</UndefinedInterfaceMethod>
163137
</file>
164138
<file src="src/Location.php">
165139
<InvalidParamDefault>
@@ -169,9 +143,6 @@
169143
<code><![CDATA[$key]]></code>
170144
<code><![CDATA[$value]]></code>
171145
</MissingParamType>
172-
<MissingTemplateParam>
173-
<code><![CDATA[ArrayAccess]]></code>
174-
</MissingTemplateParam>
175146
<MixedArgument>
176147
<code><![CDATA[$key]]></code>
177148
</MixedArgument>
@@ -185,13 +156,24 @@
185156
<code><![CDATA[is_null($value) ? false : $value]]></code>
186157
<code><![CDATA[is_null($value) ? false : $value]]></code>
187158
</MixedReturnStatement>
159+
<PossiblyNullArgument>
160+
<code><![CDATA[$this->city]]></code>
161+
<code><![CDATA[$this->state]]></code>
162+
</PossiblyNullArgument>
163+
<PropertyTypeCoercion>
164+
<code><![CDATA[$this->attributes]]></code>
165+
</PropertyTypeCoercion>
166+
</file>
167+
<file src="src/Services/AbstractService.php">
168+
<MixedAssignment>
169+
<code><![CDATA[$configValue]]></code>
170+
</MixedAssignment>
188171
</file>
189172
<file src="src/Services/IPApi.php">
190173
<MixedArgument>
191-
<code><![CDATA[$data[0]]]></code>
192-
<code><![CDATA[$data[0]]]></code>
193174
<code><![CDATA[$json->countryCode]]></code>
194175
<code><![CDATA[$path]]></code>
176+
<code><![CDATA[$path]]></code>
195177
<code><![CDATA[$this->config('continent_path')]]></code>
196178
<code><![CDATA[$this->config('continent_path')]]></code>
197179
</MixedArgument>
@@ -218,6 +200,10 @@
218200
<MixedInferredReturnType>
219201
<code><![CDATA[string]]></code>
220202
</MixedInferredReturnType>
203+
<MixedOperand>
204+
<code><![CDATA[$json->message]]></code>
205+
<code><![CDATA[$json->message]]></code>
206+
</MixedOperand>
221207
<MixedPropertyFetch>
222208
<code><![CDATA[$json->message]]></code>
223209
</MixedPropertyFetch>
@@ -230,14 +216,16 @@
230216
<PropertyNotSetInConstructor>
231217
<code><![CDATA[$continents]]></code>
232218
</PropertyNotSetInConstructor>
219+
<RedundantCastGivenDocblockType>
220+
<code><![CDATA[(string) $line]]></code>
221+
</RedundantCastGivenDocblockType>
233222
<RedundantConditionGivenDocblockType>
234223
<code><![CDATA[$this->client->getErrors() !== null]]></code>
235224
<code><![CDATA[$this->client->getErrors() !== null]]></code>
236225
</RedundantConditionGivenDocblockType>
237226
</file>
238227
<file src="src/Services/IPData.php">
239228
<MixedArgument>
240-
<code><![CDATA[$data[0]]]></code>
241229
<code><![CDATA[$json]]></code>
242230
<code><![CDATA[$json]]></code>
243231
<code><![CDATA[$json]]></code>
@@ -277,7 +265,6 @@
277265
</file>
278266
<file src="src/Services/IPFinder.php">
279267
<MixedArgument>
280-
<code><![CDATA[$data[0]]]></code>
281268
<code><![CDATA[$json]]></code>
282269
</MixedArgument>
283270
<MixedAssignment>
@@ -289,7 +276,6 @@
289276
</file>
290277
<file src="src/Services/IPGeoLocation.php">
291278
<MixedArgument>
292-
<code><![CDATA[$data[0]]]></code>
293279
<code><![CDATA[$json]]></code>
294280
</MixedArgument>
295281
<MixedAssignment>
@@ -314,6 +300,7 @@
314300
<code><![CDATA[$lang]]></code>
315301
<code><![CDATA[$lang]]></code>
316302
<code><![CDATA[$this->config('database_path')]]></code>
303+
<code><![CDATA[$this->config('database_path')]]></code>
317304
<code><![CDATA[$this->config('locales', ['en'])]]></code>
318305
<code><![CDATA[$this->config('update_url')]]></code>
319306
</MixedArgument>
@@ -342,7 +329,6 @@
342329
<code><![CDATA[$lang]]></code>
343330
<code><![CDATA[$this->config('license_key')]]></code>
344331
<code><![CDATA[$this->config('locales', ['en'])]]></code>
345-
<code><![CDATA[$this->config('user_id')]]></code>
346332
</MixedArgument>
347333
<MixedArrayOffset>
348334
<code><![CDATA[$localizations[$lang]]]></code>

rector.php

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
7+
return RectorConfig::configure()
8+
->withPaths([
9+
__DIR__ . '/src',
10+
__DIR__ . '/tests',
11+
])
12+
->withSets([
13+
\Rector\Set\ValueObject\LevelSetList::UP_TO_PHP_81,
14+
\Rector\Set\ValueObject\SetList::CODE_QUALITY,
15+
\Rector\Set\ValueObject\SetList::CODING_STYLE,
16+
\Rector\Set\ValueObject\SetList::TYPE_DECLARATION,
17+
\Rector\Set\ValueObject\SetList::PRIVATIZATION,
18+
\Rector\PHPUnit\Set\PHPUnitSetList::PHPUNIT_CODE_QUALITY,
19+
\Rector\PHPUnit\Set\PHPUnitSetList::PHPUNIT_100,
20+
])
21+
->withRules([
22+
\Rector\Php55\Rector\String_\StringClassNameToClassConstantRector::class,
23+
\Rector\CodingStyle\Rector\ArrowFunction\StaticArrowFunctionRector::class,
24+
\Rector\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector::class,
25+
\Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector::class,
26+
\Rector\CodingStyle\Rector\Closure\StaticClosureRector::class,
27+
28+
])
29+
->withParallel();

src/Cache.php

+5-13
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,10 @@ class Cache
1414
/**
1515
* Instance of cache manager.
1616
*
17-
* @var \Illuminate\Cache\CacheManager
17+
* @var \Illuminate\Cache\CacheManager|\Illuminate\Cache\TaggedCache
1818
*/
1919
protected $cache;
2020

21-
/**
22-
* Lifetime of the cache.
23-
*
24-
* @var int
25-
*/
26-
protected $expires;
27-
2821
/** Cache prefix */
2922
protected string $prefix = '';
3023

@@ -35,10 +28,9 @@ class Cache
3528
* @param array $tags
3629
* @param int $expires
3730
*/
38-
public function __construct(CacheManager $cache, $tags, $expires = 30)
31+
public function __construct(CacheManager $cache, $tags, protected int $expires = 30)
3932
{
4033
$this->cache = ($tags === [] || !$cache->supportsTags()) ? $cache : $cache->tags($tags);
41-
$this->expires = $expires;
4234
}
4335

4436
/**
@@ -57,7 +49,7 @@ public function setPrefix(?string $prefix = null): void
5749
*
5850
* @return Location|null
5951
*/
60-
public function get($name)
52+
public function get(string $name): ?\InteractionDesignFoundation\GeoIP\Location
6153
{
6254
/** @psalm-var LocationArray|null $value */
6355
$value = $this->cache->get($this->prefix . $name);
@@ -75,7 +67,7 @@ public function get($name)
7567
*
7668
* @return bool
7769
*/
78-
public function set($name, Location $location)
70+
public function set(string $name, Location $location)
7971
{
8072
return $this->cache->put($this->prefix . $name, $location->toArray(), $this->expires);
8173
}
@@ -85,7 +77,7 @@ public function set($name, Location $location)
8577
*
8678
* @return bool
8779
*/
88-
public function flush()
80+
public function flush(): bool
8981
{
9082
return $this->cache->flush();
9183
}

src/Console/Clear.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ public function handle(): int
3939
*
4040
* @return bool
4141
*/
42-
protected function isSupported()
42+
protected function isSupported(): bool
4343
{
44-
return empty(app('geoip')->config('cache_tags')) === false
45-
&& in_array(config('cache.default'), ['file', 'database'], true) === false;
44+
return (empty(app('geoip')->config('cache_tags')) === false)
45+
&& (in_array(config('cache.default'), ['file', 'database'], true) === false);
4646
}
4747

4848
/**

src/Console/Update.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,17 @@ public function handle(): int
2727
{
2828
// Get default service
2929
try {
30+
/** @var \InteractionDesignFoundation\GeoIP\Contracts\ServiceInterface $service */
3031
$service = app('geoip')->getService();
31-
} catch (MissingConfigurationException $e) {
32-
$this->components->error($e->getMessage());
32+
} catch (MissingConfigurationException $missingConfigurationException) {
33+
$this->components->error($missingConfigurationException->getMessage());
3334

3435
return static::FAILURE;
3536
}
3637

3738
// Ensure the selected service supports updating
3839
if (method_exists($service, 'update') === false) {
39-
$this->info('The current service "' . get_class($service) . '" does not support updating.');
40+
$this->info('The current service "' . $service::class . '" does not support updating.');
4041

4142
return static::SUCCESS;
4243
}

src/Contracts/ServiceInterface.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ public function hydrate(array $attributes = []);
4242
* Get configuration value.
4343
*
4444
* @param string $key
45-
* @param mixed $default
4645
*
4746
* @return mixed
4847
*/
49-
public function config($key, $default = null);
48+
public function config($key, mixed $default = null);
5049
}

src/Facades/GeoIP.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* @method static string getClientIP()
1212
* @method static string getCurrency(string $iso)
1313
* @method static \InteractionDesignFoundation\GeoIP\Contracts\ServiceInterface getService()
14-
* @mixin \InteractionDesignFoundation\GeoIP\GeoIP
14+
* @see \InteractionDesignFoundation\GeoIP\GeoIP
1515
*/
1616
class GeoIP extends Facade
1717
{

0 commit comments

Comments
 (0)