for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* This file is a part of Woketo package.
*
* (c) Nekland <[email protected]>
* For the full license, take a look to the LICENSE file
* on the root directory of this project
*/
namespace Nekland\Woketo\Client;
use Nekland\Woketo\Message\MessageHandlerInterface;
class WebSocketClient
{
* @var int
private $port;
* @var string
private $host;
* @var array
private $config;
public function __construct(int $port, string $host, array $config = [], $connectorFactory = null)
$this->port = $port;
$this->host = $host;
$this->connectorFactory = $connectorFactory ?: new ConnectorFactory();
connectorFactory
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->setConfig($config);
}
public function start(MessageHandlerInterface $handler)
$handler
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.
if ($this->config['prod'] && \extension_loaded('xdebug')) {
throw new \Exception('xdebug is enabled, it\'s a performance issue. Disable that extension or specify "prod" option to false.');
$connection = new Connection($this->connectorFactory->createConnector());
$connection
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
$myVar = 'Value'; $higher = false; if (rand(1, 6) > 3) { $higher = true; } else { $higher = false; }
Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.
$myVar
$higher
* @param array $config
* @return self
public function setConfig(array $config = [])
$this->config = array_merge([
'prod' => true
], $config);
return $this;
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: