Skip to content

Commit

Permalink
Fix QA
Browse files Browse the repository at this point in the history
  • Loading branch information
gmazzap committed Apr 16, 2024
1 parent 24bb1fc commit fe6b000
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Inpsyde/Sniffs/CodeQuality/DisableMagicSerializeSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public function process(File $phpcsFile, $stackPtr): void
if (in_array($name, $this->disabledFunctions, true)) {
$phpcsFile->addError(
sprintf(
'The method "%s" is deprecated, please use __serialize and __unserialize instead.',
'The method "%s" is deprecated, '
. 'please use __serialize and __unserialize instead.',
$name
),
$stackPtr,
Expand Down
7 changes: 4 additions & 3 deletions Inpsyde/Sniffs/CodeQuality/DisableSerializeInterfaceSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class DisableSerializeInterfaceSniff implements Sniff
{
/**
* @return list<int>
* @return list<int|string>
*/
public function register(): array
{
Expand All @@ -33,7 +33,7 @@ public function register(): array
public function process(File $phpcsFile, $stackPtr): void
{
// phpcs:enable Inpsyde.CodeQuality.ArgumentTypeDeclaration
$tokenCode = $phpcsFile->getTokens()[$stackPtr]['code'];
$tokenCode = $phpcsFile->getTokens()[$stackPtr]['code'] ?? null;
$find = ($tokenCode === \T_INTERFACE)
? ObjectDeclarations::findExtendedInterfaceNames($phpcsFile, $stackPtr)
: ObjectDeclarations::findImplementedInterfaceNames($phpcsFile, $stackPtr);
Expand All @@ -43,7 +43,8 @@ public function process(File $phpcsFile, $stackPtr): void
}

$phpcsFile->addError(
'The Serializable interface is deprecated, please use __serialize and __unserialize instead.',
'The Serializable interface is deprecated, '
. 'please use __serialize and __unserialize instead.',
$stackPtr,
'Found'
);
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/fixtures/disallow-magic-serialize.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

class Foo {

// @phpcsErrorOnNextLine
public function __serialize(): array
{
return [];
Expand Down Expand Up @@ -37,7 +36,6 @@ public function wakeup(): array
return [];
}

// @phpcsErrorOnNextLine
public function __unserialize(): array
{
return [];
Expand Down
58 changes: 58 additions & 0 deletions tests/unit/fixtures/disallow-serialize-interface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

// @phpcsSniff Inpsyde.CodeQuality.DisableSerializeInterface

// @phpcsErrorOnNextLine
class One implements Serializable {

public function serialize()
{
return null;
}

public function unserialize($data)
{
}
}

// @phpcsErrorOnNextLine
$x = new class implements Serializable {

public function serialize()
{
return null;
}

public function unserialize($data)
{
}
};

class Three {

public function serialize()
{
return null;
}

public function unserialize($data)
{
}
}

// @phpcsErrorOnNextLine
interface Two extends Serializable {

}

class Four {

public function __serialize()
{
return null;
}

public function __unserialize($data)
{
}
}

0 comments on commit fe6b000

Please sign in to comment.