for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace TomPHP\HalClient;
use Assert\Assertion;
use TomPHP\HalClient\Exception\UnknownContentTypeException;
use TomPHP\HalClient\HttpClient\GuzzleHttpClient;
use TomPHP\HalClient\Processor\HalJsonProcessor;
final class Client implements ResourceFetcher
{
/** @var HttpClient */
private $httpClient;
/** @var Processor[] */
private $processors;
/** @return self */
public static function create()
return new self(new GuzzleHttpClient(), [new HalJsonProcessor()]);
}
/** @param Processor[] $processors */
public function __construct(HttpClient $httpClient, array $processors)
Assertion::allIsInstanceOf($processors, Processor::class);
$this->httpClient = $httpClient;
foreach ($processors as $processor) {
$this->processors[$processor->getContentType()] = $processor;
public function get($url)
$response = $this->httpClient->get($url);
$contentTypes = $response->getHeader('content-type');
$contentType = array_shift($contentTypes);
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
$a = "a"; $ab = "ab"; $abc = "abc";
will produce issues in the first and second line, while this second example
will produce no issues.
if (!array_key_exists($contentType, $this->processors)) {
throw new UnknownContentTypeException($contentType);
$processor = $this->processors[$contentType];
return $processor->process($response, $this);
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.