Reduce isset use

This commit is contained in:
Dennis Eichhorn 2018-02-26 20:05:02 +01:00
parent 3c3c7fe251
commit ab96277fb1
23 changed files with 65 additions and 65 deletions

View File

@ -320,15 +320,15 @@ class Account implements ArrayableInterface, \JsonSerializable
*/
public function hasPermission(int $permission, int $unit = null, string $app = null, int $module = null, int $type = null, $element = null, $component = null) : bool
{
$app = isset($app) ? strtolower($app) : $app;
$app = $app !== null ? strtolower($app) : $app;
foreach ($this->permissions as $p) {
if (($p->getUnit() === $unit || $p->getUnit() === null || !isset($unit))
&& ($p->getApp() === $app || $p->getApp() === null || !isset($app))
&& ($p->getModule() === $module || $p->getModule() === null || !isset($module))
&& ($p->getType() === $type || $p->getType() === null || !isset($type))
&& ($p->getElement() === $element || $p->getElement() === null || !isset($element))
&& ($p->getComponent() === $component || $p->getComponent() === null || !isset($component))
if (($p->getUnit() === $unit || $p->getUnit() === null || $unit === null)
&& ($p->getApp() === $app || $p->getApp() === null || $app === null)
&& ($p->getModule() === $module || $p->getModule() === null || $module === null)
&& ($p->getType() === $type || $p->getType() === null || $type === null)
&& ($p->getElement() === $element || $p->getElement() === null || $element === null)
&& ($p->getComponent() === $component || $p->getComponent() === null || $component === null)
&& ($p->getPermission() | $permission) === $p->getPermission()
) {
return true;

View File

@ -161,7 +161,7 @@ abstract class ConnectionAbstract implements ConnectionInterface
*/
public function getGrammar() : Grammar
{
if (!isset($this->grammar)) {
if ($this->grammar === null) {
$this->grammar = new Grammar();
}
@ -173,7 +173,7 @@ abstract class ConnectionAbstract implements ConnectionInterface
*/
public function getSchemaGrammar() : SchemaGrammar
{
if (!isset($this->schemaGrammar)) {
if ($this->schemaGrammar === null) {
$this->schemaGrammar = new SchemaGrammar();
}

View File

@ -55,7 +55,7 @@ class SqliteConnection extends ConnectionAbstract
{
$this->close();
$this->dbdata = isset($dbdata) ? $dbdata : $this->dbdata;
$this->dbdata = $dbdata !== null ? $dbdata : $this->dbdata;
$this->prefix = $dbdata['prefix'];
try {

View File

@ -486,7 +486,7 @@ class Builder extends BuilderAbstract
*/
public function where($columns, $operator = null, $values = null, $boolean = 'and') : Builder
{
if (isset($operator) && !is_array($operator) && !in_array(strtolower($operator), self::OPERATORS)) {
if ($operator !== null && !is_array($operator) && !in_array(strtolower($operator), self::OPERATORS)) {
throw new \InvalidArgumentException('Unknown operator.');
}

View File

@ -126,7 +126,7 @@ class L11nManager
*/
public function getModuleLanguage(string $language, string $module = null) : array
{
if (!isset($module) && isset($this->language[$language])) {
if ($module === null && isset($this->language[$language])) {
return $this->language[$language];
} elseif (isset($this->language[$language], $this->language[$language][$module])) {
return $this->language[$language][$module];

View File

@ -64,7 +64,7 @@ class MeasureOfDispersion
*/
public static function empiricalVariationCoefficient(array $values, float $mean = null) : float
{
$mean = isset($mean) ? $mean : Average::arithmeticMean($values);
$mean = $mean !== null ? $mean : Average::arithmeticMean($values);
if ($mean === 0) {
throw new ZeroDevisionException();
@ -89,7 +89,7 @@ class MeasureOfDispersion
*/
public static function standardDeviation(array $values, float $mean = null) : float
{
$mean = isset($mean) ? $mean : Average::arithmeticMean($values);
$mean = $mean !== null ? $mean : Average::arithmeticMean($values);
$sum = 0.0;
foreach ($values as $value) {
@ -156,7 +156,7 @@ class MeasureOfDispersion
throw new ZeroDevisionException();
}
$mean = $hasProbability ? Average::weightedAverage($values, $probabilities) : (isset($mean) ? $mean : Average::arithmeticMean($values));
$mean = $hasProbability ? Average::weightedAverage($values, $probabilities) : ($mean !== null ? $mean : Average::arithmeticMean($values));
$sum = 0;
foreach ($values as $key => $value) {
@ -196,8 +196,8 @@ class MeasureOfDispersion
throw new InvalidDimensionException($count . 'x' . count($y));
}
$xMean = isset($meanX) ? $meanX : Average::arithmeticMean($x);
$yMean = isset($meanY) ? $meanY : Average::arithmeticMean($y);
$xMean = $meanX !== null ? $meanX : Average::arithmeticMean($x);
$yMean = $meanY !== null ? $meanY : Average::arithmeticMean($y);
$sum = 0.0;
@ -234,7 +234,7 @@ class MeasureOfDispersion
*/
public static function meanDeviation(array $x, float $mean = null) : float
{
$mean = isset($mean) ? $mean : Average::arithmeticMean($x);
$mean = $mean !== null ? $mean : Average::arithmeticMean($x);
$sum = 0.0;
foreach ($x as $xi) {
@ -256,7 +256,7 @@ class MeasureOfDispersion
*/
public static function meanAbsoluteDeviation(array $x, float $mean = null) : float
{
$mean = isset($mean) ? $mean : Average::arithmeticMean($x);
$mean = $mean !== null ? $mean : Average::arithmeticMean($x);
$sum = 0.0;
foreach ($x as $xi) {
@ -278,7 +278,7 @@ class MeasureOfDispersion
*/
public static function squaredMeanDeviation(array $x, float $mean = null) : float
{
$mean = isset($mean) ? $mean : Average::arithmeticMean($x);
$mean = $mean !== null ? $mean : Average::arithmeticMean($x);
$sum = 0.0;
foreach ($x as $xi) {

View File

@ -97,7 +97,7 @@ class Request extends RequestAbstract
*/
private function init() /* : void */
{
if (!isset($this->uri)) {
if ($this->uri === null) {
$this->initCurrentRequest();
$this->lock();
$this->cleanupGlobals();
@ -263,7 +263,7 @@ class Request extends RequestAbstract
*/
public function getRequestInfo() : array
{
if (!isset($this->info)) {
if ($this->info === null) {
$this->info['browser'] = $this->getBrowser();
$this->info['os'] = $this->getOS();
}
@ -280,7 +280,7 @@ class Request extends RequestAbstract
*/
public function getBrowser() : string
{
if (!isset($this->browser)) {
if ($this->browser === null) {
$arr = BrowserType::getConstants();
$httpUserAgent = strtolower($_SERVER['HTTP_USER_AGENT']);
@ -321,7 +321,7 @@ class Request extends RequestAbstract
*/
public function getOS() : string
{
if (!isset($this->os)) {
if ($this->os === null) {
$arr = OSType::getConstants();
$httpUserAgent = strtolower($_SERVER['HTTP_USER_AGENT']);
@ -444,7 +444,7 @@ class Request extends RequestAbstract
*/
public function getMethod() : string
{
if (!isset($this->method)) {
if ($this->method === null) {
$this->method = $_SERVER['REQUEST_METHOD'] ?? RequestMethod::GET;
}

View File

@ -127,7 +127,7 @@ class EmailAbstract
*/
public function disconnect() /* : void */
{
if (!isset($this->con)) {
if ($this->con === null) {
imap_close($this->con);
$this->con = null;
}
@ -148,7 +148,7 @@ class EmailAbstract
$this->mailbox = substr($this->mailbox, 0, -1) . ($this->ssl ? '/ssl/validate-cert' : '/novalidate-cert') . '}';
// /novalidate-cert
if (!isset($this->con)) {
if ($this->con === null) {
$this->con = imap_open($this->mailbox . 'INBOX', $user, $pass);
}
}

View File

@ -203,7 +203,7 @@ abstract class RequestAbstract implements MessageInterface
*/
public function getData($key = null)
{
if (!isset($key)) {
if ($key === null) {
return $this->data;
}

View File

@ -140,7 +140,7 @@ class ModuleManager
*/
public function getUriLoad(RequestAbstract $request) : array
{
if (!isset($this->uriLoad)) {
if ($this->uriLoad === null) {
switch ($this->app->dbPool->get('select')->getType()) {
case DatabaseType::MYSQL:
$uriHash = $request->getHash();
@ -233,7 +233,7 @@ class ModuleManager
*/
public function getAllModules() : array
{
if (!isset($this->all)) {
if ($this->all === null) {
chdir($this->modulePath);
$files = glob('*', GLOB_ONLYDIR);
$c = count($files);

View File

@ -155,11 +155,11 @@ class BinaryTree extends Tree
$left = $this->getLeft($node);
$right = $this->getRight($node);
if (isset($left)) {
if ($left !== null) {
$this->getVerticalOrder($left, $horizontalDistance - 1, $order);
}
if (isset($right)) {
if ($right !== null) {
$this->getVerticalOrder($right, $horizontalDistance + 1, $order);
}
}
@ -198,18 +198,18 @@ class BinaryTree extends Tree
*/
public function isSymmetric(Node $node1 = null, Node $node2 = null) : bool
{
if (!isset($node1) && !isset($node2)) {
if ($node1 === null && $node2 === null) {
return true;
}
$left1 = $this->getLeft($node1);
$right1 = $this->getRight($node1);
$left2 = isset($node2) ? $this->getLeft($node1) : $this->getLeft($node2);
$right2 = isset($node2) ? $this->getRight($node1) : $this->getRight($node2);
$left2 = $node2 !== null ? $this->getLeft($node1) : $this->getLeft($node2);
$right2 = $node2 !== null ? $this->getRight($node1) : $this->getRight($node2);
// todo: compare values? true symmetry requires the values to be the same
if (isset($node1, $node2)) {
if ($node1 !== null && $node2 !== null) {
return $this->isSymmetric($left1, $right2) && $this->isSymmetric($right1, $left2);
}

View File

@ -74,7 +74,7 @@ class Tree extends Graph
{
$currentNode = $node ?? $this->root;
if (!isset($currentNode)) {
if ($currentNode === null) {
return 0;
}
@ -101,7 +101,7 @@ class Tree extends Graph
{
$currentNode = $node ?? $this->root;
if (!isset($currentNode)) {
if ($currentNode === null) {
return 0;
}

View File

@ -300,7 +300,7 @@ class Directory extends FileAbstract implements DirectoryInterface
*/
public function offsetSet($offset, $value)
{
if (!isset($offset)) {
if ($offset === null) {
$this->addNode($value);
} else {
$this->nodes[$offset] = $value;

View File

@ -39,7 +39,7 @@ class FtpStorage extends StorageAbstract
public static function getInstance() : StorageAbstract
{
if (!isset(self::$instance)) {
if (self::$instance === null) {
self::$instance = new self();
}

View File

@ -470,7 +470,7 @@ class Directory extends FileAbstract implements DirectoryInterface
*/
public function offsetSet($offset, $value)
{
if (!isset($offset)) {
if ($offset === null) {
$this->addNode($value);
} else {
$this->nodes[$offset] = $value;

View File

@ -55,7 +55,7 @@ class LocalStorage extends StorageAbstract
*/
public static function getInstance() : StorageAbstract
{
if (!isset(self::$instance)) {
if (self::$instance === null) {
self::$instance = new self();
}

View File

@ -275,7 +275,7 @@ class Http implements UriInterface
*/
public function getQuery(string $key = null) : string
{
if (isset($key)) {
if ($key !== null) {
$key = strtolower($key);
return $this->query[$key] ?? '';
@ -338,7 +338,7 @@ class Http implements UriInterface
public function getAuthority() : string
{
return ($this->getUser() !== '' ? $this->getUser() . '@' : '') . $this->host
. (isset($this->port) && $this->port !== 0 ? ':' . $this->port : '');
. ($this->port !== null && $this->port !== 0 ? ':' . $this->port : '');
}
/**

View File

@ -246,7 +246,7 @@ class Repository
throw new \Exception('Already repository');
}
if (isset($source)) {
if ($source !== null) {
return stripos($source, '//') !== false ? $this->cloneRemote($source) : $this->cloneFrom($source);
}
@ -688,11 +688,11 @@ class Repository
*/
public function getContributors(\DateTime $start = null, \DateTime $end = null) : array
{
if (!isset($start)) {
if ($start === null) {
$start = new \DateTime('1970-12-31');
}
if (!isset($end)) {
if ($end === null) {
$end = new \DateTime('now');
}
@ -727,11 +727,11 @@ class Repository
*/
public function getCommitsCount(\DateTime $start = null, \DateTime $end = null) : array
{
if (!isset($start)) {
if ($start === null) {
$start = new \DateTime('1970-12-31');
}
if (!isset($end)) {
if ($end === null) {
$end = new \DateTime('now');
}
@ -760,11 +760,11 @@ class Repository
*/
public function getAdditionsRemovalsByContributor(Author $author, \DateTime $start = null, \DateTime $end = null) : array
{
if (!isset($start)) {
if ($start === null) {
$start = new \DateTime('1900-01-01');
}
if (!isset($end)) {
if ($end === null) {
$end = new \DateTime('now');
}
@ -811,15 +811,15 @@ class Repository
*/
public function getCommitsBy(\DateTime $start = null, \DateTime $end = null, Author $author = null) : array
{
if (!isset($start)) {
if ($start === null) {
$start = new \DateTime('1970-12-31');
}
if (!isset($end)) {
if ($end === null) {
$end = new \DateTime('now');
}
if (!isset($author)) {
if ($author === null) {
$author = '';
} else {
$author = ' --author=' . escapeshellarg($author->getName()) . '';

View File

@ -170,7 +170,7 @@ class Markdown
if (isset($currentBlock['continuable'])) {
$block = self::{'block' . $currentBlock['type'] . 'Continue'}($lineArray, $currentBlock);
if (isset($block)) {
if ($block !== null) {
$currentBlock = $block;
continue;
@ -191,7 +191,7 @@ class Markdown
foreach ($blockTypes as $blockType) {
$block = self::{'block' . $blockType}($lineArray, $currentBlock);
if (isset($block)) {
if ($block !== null) {
$block['type'] = $blockType;
if (!isset($block['identified'])) {
@ -243,7 +243,7 @@ class Markdown
protected static function blockCode(array $lineArray, array $block = null) /* : ?array */
{
if (isset($block) && !isset($block['type']) && !isset($block['interrupted'])) {
if ($block !== null && !isset($block['type']) && !isset($block['interrupted'])) {
return;
}
@ -676,7 +676,7 @@ class Markdown
foreach (self::$inlineTypes[$marker] as $inlineType) {
$inline = self::{'inline' . $inlineType}($excerptArray);
if (!isset($inline)) {
if ($inline === null) {
continue;
}
@ -794,7 +794,7 @@ class Markdown
$excerpt['text'] = substr($excerpt['text'], 1);
$link = self::inlineLink($excerpt);
if (!isset($link)) {
if ($link === null) {
return;
}

View File

@ -68,7 +68,7 @@ class ArrayParser
return '"' . $value . '"';
} elseif (is_scalar($value)) {
return (string) $value;
} elseif (!isset($value)) {
} elseif ($value === null) {
return 'null';
} elseif (is_bool($value)) {
return $value ? 'true' : 'false';

View File

@ -100,7 +100,7 @@ class Interval implements \Serializable
{
$this->start = new \DateTime('now');
if (isset($interval)) {
if ($interval !== null) {
$this->unserialize($interval);
}
}

View File

@ -39,7 +39,7 @@ final class Validator extends ValidatorAbstract
*/
public static function isValid($var, array $constraints = null) : bool
{
if (!isset($constraints)) {
if ($constraints === null) {
return true;
}

View File

@ -85,7 +85,7 @@ class View extends ViewAbstract
$this->app = $app;
$this->request = $request;
$this->response = $response;
$this->l11n = isset($response) ? $response->getHeader()->getL11n() : null;
$this->l11n = $response !== null ? $response->getHeader()->getL11n() : null;
}
/**
@ -174,7 +174,7 @@ class View extends ViewAbstract
*/
public function getText($translation, string $module = null, string $theme = null) : string
{
if (!isset($module)) {
if ($module === null) {
$match = '/Modules/';
if (($start = strripos($this->template, $match)) === false) {
@ -186,7 +186,7 @@ class View extends ViewAbstract
$module = substr($this->template, $start, $end - $start);
}
if (!isset($theme)) {
if ($theme === null) {
$match = '/Theme/';
if (($start = strripos($this->template, $match)) === false) {