Skip to content

Commit fe6b000

Browse files
committed
Fix QA
1 parent 24bb1fc commit fe6b000

File tree

4 files changed

+64
-6
lines changed

4 files changed

+64
-6
lines changed

Inpsyde/Sniffs/CodeQuality/DisableMagicSerializeSniff.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public function process(File $phpcsFile, $stackPtr): void
4343
if (in_array($name, $this->disabledFunctions, true)) {
4444
$phpcsFile->addError(
4545
sprintf(
46-
'The method "%s" is deprecated, please use __serialize and __unserialize instead.',
46+
'The method "%s" is deprecated, '
47+
. 'please use __serialize and __unserialize instead.',
4748
$name
4849
),
4950
$stackPtr,

Inpsyde/Sniffs/CodeQuality/DisableSerializeInterfaceSniff.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
class DisableSerializeInterfaceSniff implements Sniff
1212
{
1313
/**
14-
* @return list<int>
14+
* @return list<int|string>
1515
*/
1616
public function register(): array
1717
{
@@ -33,7 +33,7 @@ public function register(): array
3333
public function process(File $phpcsFile, $stackPtr): void
3434
{
3535
// phpcs:enable Inpsyde.CodeQuality.ArgumentTypeDeclaration
36-
$tokenCode = $phpcsFile->getTokens()[$stackPtr]['code'];
36+
$tokenCode = $phpcsFile->getTokens()[$stackPtr]['code'] ?? null;
3737
$find = ($tokenCode === \T_INTERFACE)
3838
? ObjectDeclarations::findExtendedInterfaceNames($phpcsFile, $stackPtr)
3939
: ObjectDeclarations::findImplementedInterfaceNames($phpcsFile, $stackPtr);
@@ -43,7 +43,8 @@ public function process(File $phpcsFile, $stackPtr): void
4343
}
4444

4545
$phpcsFile->addError(
46-
'The Serializable interface is deprecated, please use __serialize and __unserialize instead.',
46+
'The Serializable interface is deprecated, '
47+
. 'please use __serialize and __unserialize instead.',
4748
$stackPtr,
4849
'Found'
4950
);

tests/unit/fixtures/disallow-magic-serialize.php

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

55
class Foo {
66

7-
// @phpcsErrorOnNextLine
87
public function __serialize(): array
98
{
109
return [];
@@ -37,7 +36,6 @@ public function wakeup(): array
3736
return [];
3837
}
3938

40-
// @phpcsErrorOnNextLine
4139
public function __unserialize(): array
4240
{
4341
return [];
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
// @phpcsSniff Inpsyde.CodeQuality.DisableSerializeInterface
4+
5+
// @phpcsErrorOnNextLine
6+
class One implements Serializable {
7+
8+
public function serialize()
9+
{
10+
return null;
11+
}
12+
13+
public function unserialize($data)
14+
{
15+
}
16+
}
17+
18+
// @phpcsErrorOnNextLine
19+
$x = new class implements Serializable {
20+
21+
public function serialize()
22+
{
23+
return null;
24+
}
25+
26+
public function unserialize($data)
27+
{
28+
}
29+
};
30+
31+
class Three {
32+
33+
public function serialize()
34+
{
35+
return null;
36+
}
37+
38+
public function unserialize($data)
39+
{
40+
}
41+
}
42+
43+
// @phpcsErrorOnNextLine
44+
interface Two extends Serializable {
45+
46+
}
47+
48+
class Four {
49+
50+
public function __serialize()
51+
{
52+
return null;
53+
}
54+
55+
public function __unserialize($data)
56+
{
57+
}
58+
}

0 commit comments

Comments
 (0)