for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* ActiveRecord for API
*
* @link https://github.com/hiqdev/yii2-hiart
* @package yii2-hiart
* @license BSD-3-Clause
* @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
*/
namespace hiqdev\hiart\auto;
use hiqdev\hiart\Query;
use hiqdev\hiart\QueryBuilderInterface;
use hiqdev\hiart\RequestCreatorInterface;
use hiqdev\hiart\RequestErrorException;
* Auto Request.
* Detects best available transport in the system.
class Request implements RequestCreatorInterface
{
* {@inheritdoc}
public function __construct(QueryBuilderInterface $builder, Query $query)
$this->builder = $builder;
builder
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
$this->query = $query;
query
}
protected $detectedClass;
public function createRequest()
if ($this->detectedClass === null) {
$this->detectedClass = $this->detectClass();
return new $this->detectedClass($this->builder, $this->query);
public $tryClasses = [
\hiqdev\hiart\guzzle\Request::class,
\hiqdev\hiart\httpclient\Request::class,
\hiqdev\hiart\curl\Request::class,
\hiqdev\hiart\stream\Request::class,
];
public function detectClass()
foreach ($this->tryClasses as $class) {
if (class_exists($class) && $class::isSupported()) {
return $class;
throw new RequestErrorException('could not auto detect Request class');
RequestErrorException::__construct()
$request
This check looks for function calls that miss required arguments.
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: