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 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) { foreach ($this->permissions as $p) {
if (($p->getUnit() === $unit || $p->getUnit() === null || !isset($unit)) if (($p->getUnit() === $unit || $p->getUnit() === null || $unit === null)
&& ($p->getApp() === $app || $p->getApp() === null || !isset($app)) && ($p->getApp() === $app || $p->getApp() === null || $app === null)
&& ($p->getModule() === $module || $p->getModule() === null || !isset($module)) && ($p->getModule() === $module || $p->getModule() === null || $module === null)
&& ($p->getType() === $type || $p->getType() === null || !isset($type)) && ($p->getType() === $type || $p->getType() === null || $type === null)
&& ($p->getElement() === $element || $p->getElement() === null || !isset($element)) && ($p->getElement() === $element || $p->getElement() === null || $element === null)
&& ($p->getComponent() === $component || $p->getComponent() === null || !isset($component)) && ($p->getComponent() === $component || $p->getComponent() === null || $component === null)
&& ($p->getPermission() | $permission) === $p->getPermission() && ($p->getPermission() | $permission) === $p->getPermission()
) { ) {
return true; return true;

View File

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

View File

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

View File

@ -486,7 +486,7 @@ class Builder extends BuilderAbstract
*/ */
public function where($columns, $operator = null, $values = null, $boolean = 'and') : Builder 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.'); throw new \InvalidArgumentException('Unknown operator.');
} }

View File

@ -126,7 +126,7 @@ class L11nManager
*/ */
public function getModuleLanguage(string $language, string $module = null) : array 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]; return $this->language[$language];
} elseif (isset($this->language[$language], $this->language[$language][$module])) { } elseif (isset($this->language[$language], $this->language[$language][$module])) {
return $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 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) { if ($mean === 0) {
throw new ZeroDevisionException(); throw new ZeroDevisionException();
@ -89,7 +89,7 @@ class MeasureOfDispersion
*/ */
public static function standardDeviation(array $values, float $mean = null) : float 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; $sum = 0.0;
foreach ($values as $value) { foreach ($values as $value) {
@ -156,7 +156,7 @@ class MeasureOfDispersion
throw new ZeroDevisionException(); 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; $sum = 0;
foreach ($values as $key => $value) { foreach ($values as $key => $value) {
@ -196,8 +196,8 @@ class MeasureOfDispersion
throw new InvalidDimensionException($count . 'x' . count($y)); throw new InvalidDimensionException($count . 'x' . count($y));
} }
$xMean = isset($meanX) ? $meanX : Average::arithmeticMean($x); $xMean = $meanX !== null ? $meanX : Average::arithmeticMean($x);
$yMean = isset($meanY) ? $meanY : Average::arithmeticMean($y); $yMean = $meanY !== null ? $meanY : Average::arithmeticMean($y);
$sum = 0.0; $sum = 0.0;
@ -234,7 +234,7 @@ class MeasureOfDispersion
*/ */
public static function meanDeviation(array $x, float $mean = null) : float 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; $sum = 0.0;
foreach ($x as $xi) { foreach ($x as $xi) {
@ -256,7 +256,7 @@ class MeasureOfDispersion
*/ */
public static function meanAbsoluteDeviation(array $x, float $mean = null) : float 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; $sum = 0.0;
foreach ($x as $xi) { foreach ($x as $xi) {
@ -278,7 +278,7 @@ class MeasureOfDispersion
*/ */
public static function squaredMeanDeviation(array $x, float $mean = null) : float 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; $sum = 0.0;
foreach ($x as $xi) { foreach ($x as $xi) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -275,7 +275,7 @@ class Http implements UriInterface
*/ */
public function getQuery(string $key = null) : string public function getQuery(string $key = null) : string
{ {
if (isset($key)) { if ($key !== null) {
$key = strtolower($key); $key = strtolower($key);
return $this->query[$key] ?? ''; return $this->query[$key] ?? '';
@ -338,7 +338,7 @@ class Http implements UriInterface
public function getAuthority() : string public function getAuthority() : string
{ {
return ($this->getUser() !== '' ? $this->getUser() . '@' : '') . $this->host 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'); throw new \Exception('Already repository');
} }
if (isset($source)) { if ($source !== null) {
return stripos($source, '//') !== false ? $this->cloneRemote($source) : $this->cloneFrom($source); 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 public function getContributors(\DateTime $start = null, \DateTime $end = null) : array
{ {
if (!isset($start)) { if ($start === null) {
$start = new \DateTime('1970-12-31'); $start = new \DateTime('1970-12-31');
} }
if (!isset($end)) { if ($end === null) {
$end = new \DateTime('now'); $end = new \DateTime('now');
} }
@ -727,11 +727,11 @@ class Repository
*/ */
public function getCommitsCount(\DateTime $start = null, \DateTime $end = null) : array public function getCommitsCount(\DateTime $start = null, \DateTime $end = null) : array
{ {
if (!isset($start)) { if ($start === null) {
$start = new \DateTime('1970-12-31'); $start = new \DateTime('1970-12-31');
} }
if (!isset($end)) { if ($end === null) {
$end = new \DateTime('now'); $end = new \DateTime('now');
} }
@ -760,11 +760,11 @@ class Repository
*/ */
public function getAdditionsRemovalsByContributor(Author $author, \DateTime $start = null, \DateTime $end = null) : array public function getAdditionsRemovalsByContributor(Author $author, \DateTime $start = null, \DateTime $end = null) : array
{ {
if (!isset($start)) { if ($start === null) {
$start = new \DateTime('1900-01-01'); $start = new \DateTime('1900-01-01');
} }
if (!isset($end)) { if ($end === null) {
$end = new \DateTime('now'); $end = new \DateTime('now');
} }
@ -811,15 +811,15 @@ class Repository
*/ */
public function getCommitsBy(\DateTime $start = null, \DateTime $end = null, Author $author = null) : array 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'); $start = new \DateTime('1970-12-31');
} }
if (!isset($end)) { if ($end === null) {
$end = new \DateTime('now'); $end = new \DateTime('now');
} }
if (!isset($author)) { if ($author === null) {
$author = ''; $author = '';
} else { } else {
$author = ' --author=' . escapeshellarg($author->getName()) . ''; $author = ' --author=' . escapeshellarg($author->getName()) . '';

View File

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

View File

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

View File

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

View File

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

View File

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