Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Remove unnecessary ternary operators #7232

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function setCredentialColumn($credentialColumn)
public function setAmbiguityIdentity($flag)
{
if (is_int($flag)) {
$this->ambiguityIdentity = (1 === $flag ? true : false);
$this->ambiguityIdentity = (1 === $flag);
} elseif (is_bool($flag)) {
$this->ambiguityIdentity = $flag;
}
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Authentication/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function __construct($code, $identity, array $messages = array())
*/
public function isValid()
{
return ($this->code > 0) ? true : false;
return ($this->code > 0);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Db/Adapter/Driver/IbmDb2/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ protected function isI5()
return $this->i5;
}

$this->i5 = php_uname('s') == 'OS400' ? true : false;
$this->i5 = (php_uname('s') == 'OS400');
return $this->i5;
}
}
2 changes: 1 addition & 1 deletion library/Zend/Filter/Inflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function setOptions($options)
*/
public function setThrowTargetExceptionsOn($throwTargetExceptionsOn)
{
$this->throwTargetExceptionsOn = ($throwTargetExceptionsOn == true) ? true : false;
$this->throwTargetExceptionsOn = (bool) $throwTargetExceptionsOn;
return $this;
}

Expand Down
4 changes: 2 additions & 2 deletions library/Zend/Form/View/Helper/FormMultiCheckbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ protected function renderOptions(MultiCheckboxElement $element, array $options,
$label = '';
$inputAttributes = $attributes;
$labelAttributes = $globalLabelAttributes;
$selected = isset($inputAttributes['selected']) && $inputAttributes['type'] != 'radio' && $inputAttributes['selected'] != false ? true : false;
$disabled = isset($inputAttributes['disabled']) && $inputAttributes['disabled'] != false ? true : false;
$selected = (isset($inputAttributes['selected']) && $inputAttributes['type'] != 'radio' && $inputAttributes['selected']);
$disabled = (isset($inputAttributes['disabled']) && $inputAttributes['disabled']);

if (is_scalar($optionSpec)) {
$optionSpec = array(
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Json/Encoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected function __construct($cycleCheck = false, $options = array())
*/
public static function encode($value, $cycleCheck = false, $options = array())
{
$encoder = new static(($cycleCheck) ? true : false, $options);
$encoder = new static($cycleCheck, $options);

if ($value instanceof JsonSerializable) {
$value = $value->jsonSerialize();
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Json/Server/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public function getResponse()
*/
public function setReturnResponse($flag = true)
{
$this->returnResponse = ($flag) ? true : false;
$this->returnResponse = (bool) $flag;
return $this;
}

Expand Down
8 changes: 4 additions & 4 deletions library/Zend/Ldap/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ protected function loadData(array $data, $fromDataSource)
$this->originalData = array();
}
$this->children = null;
$this->markAsNew(($fromDataSource === true) ? false : true);
$this->markAsNew($fromDataSource !== true);
$this->markAsToBeDeleted(false);
}

Expand Down Expand Up @@ -295,7 +295,7 @@ public static function fromArray(array $data, $fromDataSource = false)
} else {
throw new Exception\LdapException(null, '\'dn\' key is of a wrong data type.');
}
$fromDataSource = ($fromDataSource === true) ? true : false;
$fromDataSource = ($fromDataSource === true);
$new = new static($dn, $data, $fromDataSource, null);
$new->ensureRdnAttributeValues();

Expand Down Expand Up @@ -328,7 +328,7 @@ protected function ensureRdnAttributeValues($overwrite = false)
*/
protected function markAsNew($new)
{
$this->new = ($new === false) ? false : true;
$this->new = (bool) $new;
}

/**
Expand All @@ -353,7 +353,7 @@ public function isNew()
*/
protected function markAsToBeDeleted($delete)
{
$this->delete = ($delete === true) ? true : false;
$this->delete = (bool) $delete;
}


Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Mail/Protocol/Imap.php
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ public function store(array $flags, $from, $to = null, $mode = null, $silent = t
$result = $this->requestAndResponse('STORE', array($set, $item, $flags), $silent);

if ($silent) {
return $result ? true : false;
return (bool) $result;
}

$tokens = $result;
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Mail/Storage/Pop3.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public function __get($var)
} catch (MailException\ExceptionInterface $e) {
// ignoring error
}
$this->has['uniqueid'] = $id ? true : false;
$this->has['uniqueid'] = (bool) $id;
return $this->has['uniqueid'];
}

Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Math/BigInteger/Adapter/Bcmath.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public function comp($leftOperand, $rightOperand)
public function intToBin($operand, $twoc = false)
{
$nb = chr(0);
$isNegative = (strpos($operand, '-') === 0) ? true : false;
$isNegative = (strpos($operand, '-') === 0);
$operand = ltrim($operand, '+-0');

if (empty($operand)) {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Math/BigInteger/Adapter/Gmp.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public function comp($leftOperand, $rightOperand)
public function intToBin($int, $twoc = false)
{
$nb = chr(0);
$isNegative = (strpos($int, '-') === 0) ? true : false;
$isNegative = (strpos($int, '-') === 0);
$int = ltrim($int, '+-0');

if (empty($int)) {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Soap/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ public function getLastRequest()
*/
public function setReturnResponse($flag = true)
{
$this->returnResponse = ($flag) ? true : false;
$this->returnResponse = (bool) $flag;
return $this;
}

Expand Down
4 changes: 2 additions & 2 deletions library/Zend/Stdlib/Hydrator/Filter/MethodMatchFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public function filter($property)
$pos = 0;
}
if (substr($property, $pos) === $this->method) {
return $this->exclude ? false : true;
return !$this->exclude;
}
return $this->exclude ? true : false;
return $this->exclude;
}
}
4 changes: 2 additions & 2 deletions library/Zend/Validator/Barcode/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ public function hasValidLength($value)
$found = true;
} elseif ($length == 'even') {
$count = $fixum % 2;
$found = ($count == 0) ? true : false;
$found = (0 == $count);
} elseif ($length == 'odd') {
$count = $fixum % 2;
$found = ($count == 1) ? true : false;
$found = (1 == $count);
}

return $found;
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Validator/InArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public function isValid($value)
}
}

if (in_array($value, $haystack, $this->strict == self::COMPARE_STRICT ? true : false)) {
if (in_array($value, $haystack, self::COMPARE_STRICT == $this->strict)) {
return true;
}
}
Expand Down
6 changes: 3 additions & 3 deletions library/Zend/View/Helper/Doctype.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public function getDoctypes()
*/
public function isXhtml()
{
return (stristr($this->getDoctype(), 'xhtml') ? true : false);
return (bool) stristr($this->getDoctype(), 'xhtml');
}

/**
Expand All @@ -215,7 +215,7 @@ public function isXhtml()
*/
public function isHtml5()
{
return (stristr($this->__invoke(), '<!DOCTYPE html>') ? true : false);
return (bool) stristr($this->__invoke(), '<!DOCTYPE html>');
}

/**
Expand All @@ -225,6 +225,6 @@ public function isHtml5()
*/
public function isRdfa()
{
return ($this->isHtml5() || stristr($this->getDoctype(), 'rdfa') ? true : false);
return ($this->isHtml5() || stristr($this->getDoctype(), 'rdfa'));
}
}
4 changes: 2 additions & 2 deletions library/Zend/View/Helper/HeadScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ public function toString($indent = null)
: $this->getIndent();

if ($this->view) {
$useCdata = $this->view->plugin('doctype')->isXhtml() ? true : false;
$useCdata = $this->view->plugin('doctype')->isXhtml();
} else {
$useCdata = $this->useCdata ? true : false;
$useCdata = $this->useCdata;
}

$escapeStart = ($useCdata) ? '//<![CDATA[' : '//<!--';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ protected function escape($string)
*/
public function setAutoEscape($autoEscape = true)
{
$this->autoEscape = ($autoEscape) ? true : false;
$this->autoEscape = (bool) $autoEscape;
return $this;
}

Expand Down
2 changes: 1 addition & 1 deletion library/Zend/XmlRpc/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public function fault($fault = null, $code = 404)
*/
public function setReturnResponse($flag = true)
{
$this->returnResponse = ($flag) ? true : false;
$this->returnResponse = (bool) $flag;
return $this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function testRollback()
*/
protected function isTransactionEnabled()
{
$os = php_uname('s') == 'OS400' ? true : false;
$os = (php_uname('s') == 'OS400');
if ($os) {
return ini_get('ibm_db2.i5_allow_commit') == 1;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ZendTest/Filter/DigitsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class DigitsTest extends \PHPUnit_Framework_TestCase
public function setUp()
{
if (null === static::$_unicodeEnabled) {
static::$_unicodeEnabled = (@preg_match('/\pL/u', 'a')) ? true : false;
static::$_unicodeEnabled = (bool) @preg_match('/\pL/u', 'a');
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ZendTest/Filter/PregReplaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function setUp()

public function testDetectsPcreUnicodeSupport()
{
$enabled = (@preg_match('/\pL/u', 'a')) ? true : false;
$enabled = (bool) @preg_match('/\pL/u', 'a');
$this->assertEquals($enabled, PregReplaceFilter::hasPcreUnicodeSupport());
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ZendTest/Http/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public function getMethods($providerContext, $trueMethod = null)
if ($providerContext) {
$return[] = array($cValue);
} else {
$return[strtolower($cValue)] = ($trueMethod == $cValue) ? true : false;
$return[strtolower($cValue)] = ($trueMethod == $cValue);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ZendTest/I18n/Filter/AlnumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function setUp()
$this->locale = Locale::getDefault();
$language = Locale::getPrimaryLanguage($this->locale);
static::$meansEnglishAlphabet = in_array($language, array('ja'));
static::$unicodeEnabled = (@preg_match('/\pL/u', 'a')) ? true : false;
static::$unicodeEnabled = (bool) @preg_match('/\pL/u', 'a');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/ZendTest/I18n/Filter/AlphaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function setUp()
$this->locale = Locale::getDefault();
$language = Locale::getPrimaryLanguage($this->locale);
self::$meansEnglishAlphabet = in_array($language, array('ja'));
self::$unicodeEnabled = (@preg_match('/\pL/u', 'a')) ? true : false;
self::$unicodeEnabled = (bool) @preg_match('/\pL/u', 'a');
}

/**
Expand Down
20 changes: 10 additions & 10 deletions tests/ZendTest/Session/Config/SessionConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,14 +348,14 @@ public function testCookieSecureDefaultsToIniSettings()

public function testCookieSecureIsMutable()
{
$value = ini_get('session.cookie_secure') ? false : true;
$value = !ini_get('session.cookie_secure');
$this->config->setCookieSecure($value);
$this->assertEquals($value, $this->config->getCookieSecure());
}

public function testCookieSecureAltersIniSetting()
{
$value = ini_get('session.cookie_secure') ? false : true;
$value = !ini_get('session.cookie_secure');
$this->config->setCookieSecure($value);
$this->assertEquals($value, ini_get('session.cookie_secure'));
}
Expand All @@ -369,14 +369,14 @@ public function testCookieHttpOnlyDefaultsToIniSettings()

public function testCookieHttpOnlyIsMutable()
{
$value = ini_get('session.cookie_httponly') ? false : true;
$value = !ini_get('session.cookie_httponly');
$this->config->setCookieHttpOnly($value);
$this->assertEquals($value, $this->config->getCookieHttpOnly());
}

public function testCookieHttpOnlyAltersIniSetting()
{
$value = ini_get('session.cookie_httponly') ? false : true;
$value = !ini_get('session.cookie_httponly');
$this->config->setCookieHttpOnly($value);
$this->assertEquals($value, ini_get('session.cookie_httponly'));
}
Expand All @@ -390,14 +390,14 @@ public function testUseCookiesDefaultsToIniSettings()

public function testUseCookiesIsMutable()
{
$value = ini_get('session.use_cookies') ? false : true;
$value = !ini_get('session.use_cookies');
$this->config->setUseCookies($value);
$this->assertEquals($value, (bool) $this->config->getUseCookies());
}

public function testUseCookiesAltersIniSetting()
{
$value = ini_get('session.use_cookies') ? false : true;
$value = !ini_get('session.use_cookies');
$this->config->setUseCookies($value);
$this->assertEquals($value, (bool) ini_get('session.use_cookies'));
}
Expand All @@ -411,14 +411,14 @@ public function testUseOnlyCookiesDefaultsToIniSettings()

public function testUseOnlyCookiesIsMutable()
{
$value = ini_get('session.use_only_cookies') ? false : true;
$value = !ini_get('session.use_only_cookies');
$this->config->setOption('use_only_cookies', $value);
$this->assertEquals($value, (bool) $this->config->getOption('use_only_cookies'));
}

public function testUseOnlyCookiesAltersIniSetting()
{
$value = ini_get('session.use_only_cookies') ? false : true;
$value = !ini_get('session.use_only_cookies');
$this->config->setOption('use_only_cookies', $value);
$this->assertEquals($value, (bool) ini_get('session.use_only_cookies'));
}
Expand Down Expand Up @@ -594,14 +594,14 @@ public function testUseTransSidDefaultsToIniSettings()

public function testUseTransSidIsMutable()
{
$value = ini_get('session.use_trans_sid') ? false : true;
$value = !ini_get('session.use_trans_sid');
$this->config->setOption('use_trans_sid', $value);
$this->assertEquals($value, (bool) $this->config->getOption('use_trans_sid'));
}

public function testUseTransSidAltersIniSetting()
{
$value = ini_get('session.use_trans_sid') ? false : true;
$value = !ini_get('session.use_trans_sid');
$this->config->setOption('use_trans_sid', $value);
$this->assertEquals($value, (bool) ini_get('session.use_trans_sid'));
}
Expand Down
6 changes: 3 additions & 3 deletions tests/ZendTest/View/Helper/HeadStyleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ public function testHeadStyleProxiesProperly()
->__invoke($style3, 'APPEND');
$this->assertEquals(3, count($this->helper));
$values = $this->helper->getArrayCopy();
$this->assertTrue((strstr($values[0]->content, $style2)) ? true : false);
$this->assertTrue((strstr($values[1]->content, $style1)) ? true : false);
$this->assertTrue((strstr($values[2]->content, $style3)) ? true : false);
$this->assertTrue((bool) strstr($values[0]->content, $style2));
$this->assertTrue((bool) strstr($values[1]->content, $style1));
$this->assertTrue((bool) strstr($values[2]->content, $style3));
}

public function testToStyleGeneratesValidHtml()
Expand Down
4 changes: 2 additions & 2 deletions tests/ZendTest/View/Helper/Placeholder/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ public function testIndentationIsHonored()

$lis = substr_count($string, "\n <li>");
$this->assertEquals(3, $lis);
$this->assertTrue((strstr($string, " <ul>\n")) ? true : false, $string);
$this->assertTrue((strstr($string, "\n </ul>")) ? true : false);
$this->assertTrue((bool) strstr($string, " <ul>\n"), $string);
$this->assertTrue((bool) strstr($string, "\n </ul>"));
}
}
Loading