for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php declare(strict_types=1);
/**
* @package s9e\Bencode
* @copyright Copyright (c) 2014-2021 The s9e authors
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
namespace s9e\Bencode;
use ArrayObject;
use const SORT_STRING, false, true;
use function strcmp;
class NonCompliantDecoder extends Decoder
{
* @var string Whether current dictionary needs to be sorted
protected bool $sortDictionary = false;
protected function checkDictionaryCompliance(string $key, string $lastKey): void
if (!$this->sortDictionary && strcmp($key, $lastKey) < 0)
$this->sortDictionary = true;
$sortDictionary
string
true
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.
$answer = 42; $correct = false; $correct = (bool) $answer;
}
protected function complianceError(string $message, int $offset): void
// Do nothing
protected function decodeDictionary(): ArrayObject
$previousState = $this->sortDictionary;
$this->sortDictionary
boolean
$this->sortDictionary = false;
$dictionary = parent::decodeDictionary();
if ($this->sortDictionary)
$dictionary->ksort(SORT_STRING);
$this->sortDictionary = $previousState;
return $dictionary;
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.