Changed and/or to &&/||

This commit is contained in:
Marcin Kurczewski 2014-11-10 19:14:58 +01:00
parent ed833bf7b1
commit 77983d8e20
30 changed files with 51 additions and 51 deletions

View file

@ -46,7 +46,7 @@ final class AuthController extends AbstractController
public function login()
{
if (isset($this->inputReader->userNameOrEmail) and isset($this->inputReader->password))
if (isset($this->inputReader->userNameOrEmail) && isset($this->inputReader->password))
{
$formData = new LoginFormData($this->inputReader);
$this->authService->loginFromCredentials($formData);

View file

@ -125,7 +125,7 @@ final class CommentController extends AbstractController
$comment = $this->commentService->getById($commentId);
$this->privilegeService->assertPrivilege(
($comment->getUser() and $this->privilegeService->isLoggedIn($comment->getUser()))
($comment->getUser() && $this->privilegeService->isLoggedIn($comment->getUser()))
? Privilege::EDIT_OWN_COMMENTS
: Privilege::EDIT_ALL_COMMENTS);

View file

@ -34,7 +34,7 @@ class CommentViewProxy extends AbstractViewProxy
$result->user = $this->userViewProxy->fromEntity($comment->getUser());
$result->score = $comment->getScore();
if (!empty($config[self::FETCH_OWN_SCORE]) and $this->authService->isLoggedIn())
if (!empty($config[self::FETCH_OWN_SCORE]) && $this->authService->isLoggedIn())
$result->ownScore = $this->scoreService->getUserScoreValue($this->authService->getLoggedInUser(), $comment);
}
return $result;

View file

@ -107,7 +107,7 @@ class PostViewProxy extends AbstractViewProxy
$result->history = [];
}
if (!empty($config[self::FETCH_OWN_SCORE]) and $this->authService->isLoggedIn())
if (!empty($config[self::FETCH_OWN_SCORE]) && $this->authService->isLoggedIn())
$result->ownScore = $this->scoreService->getUserScoreValue($this->authService->getLoggedInUser(), $post);
if (!empty($config[self::FETCH_FAVORITES]))

View file

@ -154,7 +154,7 @@ abstract class AbstractDao implements ICrudDao, IBatchDao
protected function findBy($columnName, $value)
{
if (is_array($value) and empty($value))
if (is_array($value) && empty($value))
return [];
$query = $this->pdo->from($this->tableName)->where($columnName, $value);
$arrayEntities = iterator_to_array($query);
@ -210,7 +210,7 @@ abstract class AbstractDao implements ICrudDao, IBatchDao
else if ($value instanceof RequirementRangedValue)
{
if ($value->getMinValue() and $value->getMaxValue())
if ($value->getMinValue() && $value->getMaxValue())
{
$sql = $sqlColumn . ' >= ? AND ' . $sqlColumn . ' <= ?';
$bindings = [$value->getMinValue(), $value->getMaxValue()];

View file

@ -103,7 +103,7 @@ class TagDao extends AbstractDao implements ICrudDao
else
continue;
if (!isset($exported[$key1]) or !isset($exported[$key2]))
if (!isset($exported[$key1]) || !isset($exported[$key2]))
continue;
if (!isset($exported[$key1][$target]))

View file

@ -25,7 +25,7 @@ class TokenDao extends AbstractDao
->where('purpose', $purpose);
$arrayEntities = iterator_to_array($query);
$entities = $this->arrayToEntities($arrayEntities);
if (!$entities or !count($entities))
if (!$entities || !count($entities))
return null;
$entity = array_shift($entities);
return $entity;

View file

@ -37,7 +37,7 @@ class UserDao extends AbstractDao implements ICrudDao
public function findByEmail($userEmail, $allowUnconfirmed = false)
{
$result = $this->findOneBy('email', $userEmail);
if (!$result and $allowUnconfirmed)
if (!$result && $allowUnconfirmed)
{
$result = $this->findOneBy('emailUnconfirmed', $userEmail);
}

View file

@ -30,7 +30,7 @@ class UploadFormData implements IValidatable
public function validate(Validator $validator)
{
if ($this->content === null and $this->url === null)
if ($this->content === null && $this->url === null)
throw new \DomainException('Neither data or URL provided.');
$validator->validatePostTags($this->tags);

View file

@ -8,7 +8,7 @@ final class InputReader extends \ArrayObject
parent::setFlags(parent::ARRAY_AS_PROPS | parent::STD_PROP_LIST);
$_PUT = [];
if (isset($_SERVER['REQUEST_METHOD']) and $_SERVER['REQUEST_METHOD'] === 'PUT')
if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT')
parse_str(file_get_contents('php://input'), $_PUT);
foreach ([$_GET, $_POST, $_PUT] as $source)

View file

@ -25,7 +25,7 @@ class MimeHelper
public static function isVideo($mime)
{
return strtolower($mime) === 'application/ogg' or preg_match('/video\//i', $mime);
return strtolower($mime) === 'application/ogg' || preg_match('/video\//i', $mime);
}
public static function isImage($mime)
@ -59,7 +59,7 @@ class MimeHelper
if ($bytes === false)
return false;
if (strncmp($bytes, 'CWS', 3) === 0 or strncmp($bytes, 'FWS', 3) === 0 or strncmp($bytes, 'ZWS', 3) === 0)
if (strncmp($bytes, 'CWS', 3) === 0 || strncmp($bytes, 'FWS', 3) === 0 || strncmp($bytes, 'ZWS', 3) === 0)
return 'application/x-shockwave-flash';
if (strncmp($bytes, "\xff\xd8\xff", 3) === 0)
@ -68,13 +68,13 @@ class MimeHelper
if (strncmp($bytes, "\x89PNG\x0d\x0a", 6) === 0)
return 'image/png';
if (strncmp($bytes, 'GIF87a', 6) === 0 or strncmp($bytes, 'GIF89a', 6) === 0)
if (strncmp($bytes, 'GIF87a', 6) === 0 || strncmp($bytes, 'GIF89a', 6) === 0)
return 'image/gif';
if (strncmp($bytes, "\x1a\x45\xdf\xa3", 4) === 0)
return 'video/webm';
if (strncmp(substr($bytes, 4), 'ftypisom', 8) === 0 or strncmp(substr($bytes, 4), 'ftypmp42', 8) === 0)
if (strncmp(substr($bytes, 4), 'ftypisom', 8) === 0 || strncmp(substr($bytes, 4), 'ftypmp42', 8) === 0)
return 'video/mp4';
if (strncmp($bytes, "\x46\x4c\x56\x01", 4) === 0)

View file

@ -11,7 +11,7 @@ class TypeHelper
return false;
if ($value === false)
return false;
if (is_array($value) and count($value) === 1)
if (is_array($value) && count($value) === 1)
return false;
if ($value === null)
return false;

View file

@ -10,7 +10,7 @@ class SelectQuery extends BaseQuery implements \Countable
public function limit($limit)
{
if ($limit === null or $limit === false)
if ($limit === null || $limit === false)
$this->limit = null;
else
$this->limit = intval($limit);
@ -87,7 +87,7 @@ class SelectQuery extends BaseQuery implements \Countable
if ($this->limit !== null)
{
$sql .= 'LIMIT ' . $this->limit;
if ($this->offset !== null and $this->offset !== 0)
if ($this->offset !== null && $this->offset !== 0)
$sql .= ' OFFSET ' . intval($this->offset);
}
$this->clauses[self::CLAUSE_LIMIT] = $sql;

View file

@ -63,7 +63,7 @@ abstract class AbstractSearchParser
};
}
if ((($flags & self::ALLOW_RANGES) === self::ALLOW_RANGES) and substr_count($text, '..') === 1)
if ((($flags & self::ALLOW_RANGES) === self::ALLOW_RANGES) && substr_count($text, '..') === 1)
{
list ($minValue, $maxValue) = explode('..', $text);
$minValue = $valueDecorator($minValue);
@ -73,7 +73,7 @@ abstract class AbstractSearchParser
$tokenValue->setMaxValue($maxValue);
return $tokenValue;
}
else if ((($flags & self::ALLOW_COMPOSITE) === self::ALLOW_COMPOSITE) and strpos($text, ',') !== false)
else if ((($flags & self::ALLOW_COMPOSITE) === self::ALLOW_COMPOSITE) && strpos($text, ',') !== false)
{
$values = explode(',', $text);
$values = array_map($valueDecorator, $values);
@ -145,7 +145,7 @@ abstract class AbstractSearchParser
}
$colonPosition = strpos($tokenText, ':');
if (($colonPosition !== false) and ($colonPosition > 0))
if (($colonPosition !== false) && ($colonPosition > 0))
{
$searchToken = new NamedSearchToken();
list ($tokenKey, $tokenValue) = explode(':', $tokenText, 2);

View file

@ -76,19 +76,19 @@ class PostSearchParser extends AbstractSearchParser
elseif ($token->getKey() === 'comment')
$this->addCommentRequirement($filter, $token);
elseif ($token->getKey() === 'special' and $token->getValue() === 'liked')
elseif ($token->getKey() === 'special' && $token->getValue() === 'liked')
{
$this->privilegeService->assertLoggedIn();
$this->addUserScoreRequirement($filter, $this->authService->getLoggedInUser()->getName(), 1, $token->isNegated());
}
elseif ($token->getKey() === 'special' and $token->getValue() === 'disliked')
elseif ($token->getKey() === 'special' && $token->getValue() === 'disliked')
{
$this->privilegeService->assertLoggedIn();
$this->addUserScoreRequirement($filter, $this->authService->getLoggedInUser()->getName(), -1, $token->isNegated());
}
elseif ($token->getKey() === 'special' and $token->getValue() === 'fav')
elseif ($token->getKey() === 'special' && $token->getValue() === 'fav')
{
$this->privilegeService->assertLoggedIn();
$token = new NamedSearchToken();
@ -109,7 +109,7 @@ class PostSearchParser extends AbstractSearchParser
elseif ($tokenText === 'id')
return PostFilter::ORDER_ID;
elseif ($tokenText === 'time' or $tokenText === 'date')
elseif ($tokenText === 'time' || $tokenText === 'date')
return PostFilter::ORDER_LAST_EDIT_TIME;
elseif ($tokenText === 'score')
@ -127,13 +127,13 @@ class PostSearchParser extends AbstractSearchParser
elseif ($tokenText === 'comment_count')
return PostFilter::ORDER_COMMENT_COUNT;
elseif ($tokenText === 'fav_time' or $tokenText === 'fav_date')
elseif ($tokenText === 'fav_time' || $tokenText === 'fav_date')
return PostFilter::ORDER_LAST_FAV_TIME;
elseif ($tokenText === 'comment_time' or $tokenText === 'comment_date')
elseif ($tokenText === 'comment_time' || $tokenText === 'comment_date')
return PostFilter::ORDER_LAST_COMMENT_TIME;
elseif ($tokenText === 'feature_time' or $tokenText === 'feature_date')
elseif ($tokenText === 'feature_time' || $tokenText === 'feature_date')
return PostFilter::ORDER_LAST_FEATURE_TIME;
else

View file

@ -47,7 +47,7 @@ class TagSearchParser extends AbstractSearchParser
elseif ($tokenText === 'name')
return TagFilter::ORDER_NAME;
elseif ($tokenText === 'creation_time' or $tokenText === 'creation_date')
elseif ($tokenText === 'creation_time' || $tokenText === 'creation_date')
return TagFilter::ORDER_CREATION_TIME;
elseif ($tokenText === 'usage_count')

View file

@ -28,7 +28,7 @@ class UserSearchParser extends AbstractSearchParser
if ($tokenText === 'name')
return UserFilter::ORDER_NAME;
elseif ($tokenText === 'registration_time' or $tokenText === 'registration_date')
elseif ($tokenText === 'registration_time' || $tokenText === 'registration_date')
return UserFilter::ORDER_REGISTRATION_TIME;
else

View file

@ -110,7 +110,7 @@ class AuthService
private function doFinalChecksOnUser($user)
{
if (!$user->isAccountConfirmed() and $this->config->security->needEmailActivationToRegister)
if (!$user->isAccountConfirmed() && $this->config->security->needEmailActivationToRegister)
throw new \DomainException('User didn\'t confirm account yet.');
if ($user->isBanned())

View file

@ -73,11 +73,11 @@ class HistoryService
{
foreach ($base[$key] as $subValue)
{
if (!isset($other[$key]) or !in_array($subValue, $other[$key]))
if (!isset($other[$key]) || !in_array($subValue, $other[$key]))
$result[] = [$key, $subValue];
}
}
elseif (!isset($other[$key]) or $base[$key] !== $other[$key])
elseif (!isset($other[$key]) || $base[$key] !== $other[$key])
{
$result[] = [$key, $value];
}

View file

@ -70,7 +70,7 @@ class ImageConverter
]);
}
if (!file_exists($targetPath) and ProgramExecutor::isProgramAvailable(self::PROGRAM_NAME_SWFRENDER))
if (!file_exists($targetPath) && ProgramExecutor::isProgramAvailable(self::PROGRAM_NAME_SWFRENDER))
{
ProgramExecutor::run(
self::PROGRAM_NAME_SWFRENDER,
@ -100,7 +100,7 @@ class ImageConverter
]);
}
if (!file_exists($targetPath) and ProgramExecutor::isProgramAvailable(self::PROGRAM_NAME_FFMPEG))
if (!file_exists($targetPath) && ProgramExecutor::isProgramAvailable(self::PROGRAM_NAME_FFMPEG))
{
ProgramExecutor::run(self::PROGRAM_NAME_FFMEPG,
[

View file

@ -37,7 +37,7 @@ class NetworkingService
if ($customFileName)
$this->httpHelper->setHeader('Content-Disposition', 'inline; filename="' . $customFileName . '"');
if (strtotime($ifModifiedSince) === $lastModified or $eTagHeader === $eTag)
if (strtotime($ifModifiedSince) === $lastModified || $eTagHeader === $eTag)
{
$this->httpHelper->setResponseCode(304);
}
@ -70,7 +70,7 @@ class NetworkingService
while (!feof($srcHandle))
{
$buffer = fread($srcHandle, 4 * 1024);
if ($maxBytes !== null and strlen($result) > $maxBytes)
if ($maxBytes !== null && strlen($result) > $maxBytes)
{
throw new \Exception(
'File is too big (maximum size: %s)',

View file

@ -69,7 +69,7 @@ class PostFeatureService
{
$previousFeaturedPost = $this->getFeaturedPost();
if (($previousFeaturedPost === null) or ($previousFeaturedPost->getId() !== $post->getId()))
if (($previousFeaturedPost === null) || ($previousFeaturedPost->getId() !== $post->getId()))
{
$post->setLastFeatureTime($this->timeService->getCurrentTime());
$post->setFeatureCount($post->getFeatureCount() + 1);

View file

@ -342,7 +342,7 @@ class PostService
if (!$userSettings)
return;
if (!empty($userSettings->listPosts) and !count($filter->getRequirementsByType(PostFilter::REQUIREMENT_SAFETY)))
if (!empty($userSettings->listPosts) && !count($filter->getRequirementsByType(PostFilter::REQUIREMENT_SAFETY)))
{
$values = [];
if (!TypeHelper::toBool($userSettings->listPosts->safe))
@ -363,7 +363,7 @@ class PostService
}
}
if (!empty($userSettings->hideDownvoted) and !count($filter->getRequirementsByType(PostFilter::REQUIREMENT_USER_SCORE)))
if (!empty($userSettings->hideDownvoted) && !count($filter->getRequirementsByType(PostFilter::REQUIREMENT_USER_SCORE)))
{
$requirementValue = new RequirementCompositeValue();
$requirementValue->setValues([$currentUser->getName(), -1]);
@ -379,7 +379,7 @@ class PostService
{
$checksumToCheck = $parent->getContentChecksum();
$postWithThisChecksum = $this->postDao->findByContentChecksum($checksumToCheck);
if ($postWithThisChecksum and $postWithThisChecksum->getId() !== $parent->getId())
if ($postWithThisChecksum && $postWithThisChecksum->getId() !== $parent->getId())
throw new \DomainException('Duplicate post: ' . $postWithThisChecksum->getIdMarkdown());
}

View file

@ -60,7 +60,7 @@ class PostSnapshotProvider implements ISnapshotProvider
static $featuredPostParam = null;
if ($featuredPostParam === null)
$featuredPostParam = $this->globalParamDao->findByKey(GlobalParam::KEY_FEATURED_POST);
$isFeatured = ($featuredPostParam and intval($featuredPostParam->getValue()) === $post->getId());
$isFeatured = ($featuredPostParam && intval($featuredPostParam->getValue()) === $post->getId());
$flags = [];
if ($post->getFlags() & Post::FLAG_LOOP)

View file

@ -70,7 +70,7 @@ class PrivilegeService
$loggedInUser = $this->authService->getLoggedInUser();
if ($userIdentifier instanceof User)
{
return $loggedInUser->getId() and ($loggedInUser->getId() === $userIdentifier->getId());
return $loggedInUser->getId() && ($loggedInUser->getId() === $userIdentifier->getId());
}
elseif (is_string($userIdentifier))
{

View file

@ -59,12 +59,12 @@ class ScoreService
public function setUserScore(User $user, Entity $entity, $scoreValue)
{
if ($scoreValue !== 1 and $scoreValue !== 0 and $scoreValue !== -1)
if ($scoreValue !== 1 && $scoreValue !== 0 && $scoreValue !== -1)
throw new \DomainException('Bad score');
$transactionFunc = function() use ($user, $entity, $scoreValue)
{
if (($scoreValue !== 1) and ($entity instanceof Post))
if (($scoreValue !== 1) && ($entity instanceof Post))
$this->favoritesDao->delete($user, $entity);
return $this->scoreDao->setUserScore($user, $entity, $scoreValue);

View file

@ -212,7 +212,7 @@ class TagService
private function updateTagName(Tag $tag, $newName)
{
$otherTag = $this->tagDao->findByName($newName);
if ($otherTag and $otherTag->getId() !== $tag->getId())
if ($otherTag && $otherTag->getId() !== $tag->getId())
throw new \DomainException('Tag with this name already exists.');
$tag->setName($newName);
}

View file

@ -114,7 +114,7 @@ class ThumbnailService
{
$sourcePath = $this->fileDao->getFullPath($sourceName);
if ($format === IImageManipulator::FORMAT_JPEG and ProgramExecutor::isProgramAvailable(self::PROGRAM_NAME_JPEGOPTIM))
if ($format === IImageManipulator::FORMAT_JPEG && ProgramExecutor::isProgramAvailable(self::PROGRAM_NAME_JPEGOPTIM))
{
ProgramExecutor::run(
self::PROGRAM_NAME_JPEGOPTIM,
@ -125,7 +125,7 @@ class ThumbnailService
]);
}
elseif ($format === IImageManipulator::FORMAT_PNG and ProgramExecutor::isProgramAvailable(self::PROGRAM_NAME_OPTIPNG))
elseif ($format === IImageManipulator::FORMAT_PNG && ProgramExecutor::isProgramAvailable(self::PROGRAM_NAME_OPTIPNG))
{
ProgramExecutor::run(
self::PROGRAM_NAME_OPTIPNG,

View file

@ -313,7 +313,7 @@ class UserService
private function assertNoUserWithThisName(User $owner, $nameToCheck)
{
$userWithThisName = $this->userDao->findByName($nameToCheck);
if ($userWithThisName and $userWithThisName->getId() !== $owner->getId())
if ($userWithThisName && $userWithThisName->getId() !== $owner->getId())
throw new \DomainException('User with this name already exists.');
}
@ -322,7 +322,7 @@ class UserService
if (!$emailToCheck)
return;
$userWithThisEmail = $this->userDao->findByEmail($emailToCheck);
if ($userWithThisEmail and $userWithThisEmail->getId() !== $owner->getId())
if ($userWithThisEmail && $userWithThisEmail->getId() !== $owner->getId())
throw new \DomainException('User with this e-mail already exists.');
}

View file

@ -138,7 +138,7 @@ final class ImageManipulatorTest extends AbstractTestCase
private static function getAutoImageManipulator()
{
if (extension_loaded('gd') and extension_loaded('imagick'))
if (extension_loaded('gd') && extension_loaded('imagick'))
{
return new ImageManipulator(
self::getImagickImageManipulator(),