8 Commits

Author SHA1 Message Date
Meritoo
0b560fdf18 Exception - 3 exceptions related to file path & content 2017-09-20 13:50:18 +02:00
Meritoo
284d403061 Fix coding standard (minor fix) 2017-09-20 12:55:25 +02:00
Meritoo
7dbb3f9b2e Tests - update namespace of PHPUnit's TestCase
Related to update versions of the "dev" packages
2017-09-20 11:58:21 +02:00
Meritoo
fba821b798 Readme - StyleCI badge - update configuration file (required to fix failed StyleCI analysis) 2017-09-20 10:56:49 +02:00
Meritoo
3985c70076 Readme - minor update 2017-09-20 09:30:06 +02:00
Meritoo
921d4e6106 composer.json - update versions of the "dev" packages 2017-09-20 09:29:19 +02:00
Meritoo
7aa2239dbd Fix coding standard (no_blank_lines_after_phpdoc, single_blank_line_before_namespace, yoda_style) 2017-09-20 09:27:56 +02:00
Meritoo
e1fefcdeae Readme - move badges below description & update description 2017-09-19 20:10:27 +02:00
26 changed files with 452 additions and 378 deletions

View File

@@ -1 +1,8 @@
preset: symfony preset: symfony
disabled:
- phpdoc_annotation_without_dot
- cast_spaces
- concat_without_spaces
- blank_line_before_return
- trim_array_spaces

View File

@@ -1,9 +1,11 @@
# Meritoo Common Library [![Travis](https://img.shields.io/travis/rust-lang/rust.svg?style=flat-square)](https://travis-ci.org/meritoo/common-library) [![Packagist](https://img.shields.io/packagist/v/meritoo/common-library.svg?style=flat-square)](https://packagist.org/packages/meritoo/common-library) [![StyleCI](https://styleci.io/repos/101790028/shield?branch=master)](https://styleci.io/repos/101790028) [![license](https://img.shields.io/github/license/meritoo/common-library.svg?style=flat-square)](https://github.com/meritoo/common-library) [![GitHub commits](https://img.shields.io/github/commits-since/meritoo/common-library/0.0.1.svg?style=flat-square)](https://github.com/meritoo/common-library) [![Coverage Status](https://coveralls.io/repos/github/meritoo/common-library/badge.svg?branch=master)](https://coveralls.io/github/meritoo/common-library?branch=master) # Meritoo Common Library
Useful classes, methods, extensions etc. Common and useful classes, methods, exceptions etc.
[![Travis](https://img.shields.io/travis/rust-lang/rust.svg?style=flat-square)](https://travis-ci.org/meritoo/common-library) [![Packagist](https://img.shields.io/packagist/v/meritoo/common-library.svg?style=flat-square)](https://packagist.org/packages/meritoo/common-library) [![StyleCI](https://styleci.io/repos/101790028/shield?branch=master)](https://styleci.io/repos/101790028) [![license](https://img.shields.io/github/license/meritoo/common-library.svg?style=flat-square)](https://github.com/meritoo/common-library) [![GitHub commits](https://img.shields.io/github/commits-since/meritoo/common-library/0.0.1.svg?style=flat-square)](https://github.com/meritoo/common-library) [![Coverage Status](https://coveralls.io/repos/github/meritoo/common-library/badge.svg?branch=master)](https://coveralls.io/github/meritoo/common-library?branch=master)
## Installation ## Installation
Run [Composer](https://getcomposer.org) to install new package: Run [Composer](https://getcomposer.org) to install this package in your project:
```bash ```bash
$ composer require meritoo/common-library $ composer require meritoo/common-library

View File

@@ -2,7 +2,7 @@
"name": "meritoo/common-library", "name": "meritoo/common-library",
"description": "Useful classes, methods, extensions etc.", "description": "Useful classes, methods, extensions etc.",
"license": "MIT", "license": "MIT",
"version": "0.0.7", "version": "0.0.9",
"authors": [ "authors": [
{ {
"name": "Meritoo.pl", "name": "Meritoo.pl",
@@ -17,13 +17,13 @@
"symfony/http-foundation": "^3.3" "symfony/http-foundation": "^3.3"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^4.8 || ^5.0", "phpunit/phpunit": "^5.7",
"squizlabs/php_codesniffer": "^2.8", "squizlabs/php_codesniffer": "^2.9",
"phpmd/phpmd": "^2.6", "phpmd/phpmd": "^2.6",
"sebastian/phpcpd": "^3.0", "sebastian/phpcpd": "^3.0",
"pdepend/pdepend": "^2.5", "pdepend/pdepend": "^2.5",
"phploc/phploc": "^3.0", "phploc/phploc": "^4.0",
"friendsofphp/php-cs-fixer": "^2.1" "friendsofphp/php-cs-fixer": "^2.6"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

550
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -109,7 +109,7 @@ class Collection implements Countable, ArrayAccess, IteratorAggregate
*/ */
public function add($element, $index = null) public function add($element, $index = null)
{ {
if ($index === null) { if (null === $index) {
$this->elements[] = $element; $this->elements[] = $element;
} else { } else {
$this->elements[$index] = $element; $this->elements[$index] = $element;
@@ -216,7 +216,7 @@ class Collection implements Countable, ArrayAccess, IteratorAggregate
{ {
$index = Arrays::getIndexOf($this->elements, $element); $index = Arrays::getIndexOf($this->elements, $element);
return $index !== null && $index !== false; return null !== $index && false !== $index;
} }
/** /**

View File

@@ -0,0 +1,31 @@
<?php
/**
* (c) Meritoo.pl, http://www.meritoo.pl
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Meritoo\Common\Exception\File;
/**
* An exception used while file with given path is empty (has no content)
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
*/
class EmptyFileException extends \Exception
{
/**
* Class constructor
*
* @param string $emptyFilePath Path of the empty file
*/
public function __construct($emptyFilePath)
{
$template = 'File with path \'%s\' is empty (has no content). Did you provide path of proper file?';
$message = sprintf($template, $emptyFilePath);
parent::__construct($message);
}
}

View File

@@ -0,0 +1,26 @@
<?php
/**
* (c) Meritoo.pl, http://www.meritoo.pl
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Meritoo\Common\Exception\File;
/**
* An exception used while path of given file is empty
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
*/
class EmptyFilePathException extends \Exception
{
/**
* Class constructor
*/
public function __construct()
{
parent::__construct('Path of the file is empty. Did you provide path of proper file?');
}
}

View File

@@ -0,0 +1,31 @@
<?php
/**
* (c) Meritoo.pl, http://www.meritoo.pl
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Meritoo\Common\Exception\File;
/**
* An exception used while file with given path does not exist
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
*/
class NotExistingFileException extends \Exception
{
/**
* Class constructor
*
* @param string $notExistingFilePath Path of not existing (or not readable) file
*/
public function __construct($notExistingFilePath)
{
$template = 'File with path \'%s\' does not exist (or is not readable). Did you provide proper path of file?';
$message = sprintf($template, $notExistingFilePath);
parent::__construct($message);
}
}

View File

@@ -12,7 +12,7 @@ use DateTime;
use Generator; use Generator;
use Meritoo\Common\Exception\Type\UnknownOopVisibilityTypeException; use Meritoo\Common\Exception\Type\UnknownOopVisibilityTypeException;
use Meritoo\Common\Type\OopVisibilityType; use Meritoo\Common\Type\OopVisibilityType;
use PHPUnit_Framework_TestCase; use PHPUnit\Framework\TestCase;
use ReflectionClass; use ReflectionClass;
use ReflectionMethod; use ReflectionMethod;
@@ -22,7 +22,7 @@ use ReflectionMethod;
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl> * @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl * @copyright Meritoo.pl
*/ */
abstract class BaseTestCase extends PHPUnit_Framework_TestCase abstract class BaseTestCase extends TestCase
{ {
/** /**
* Provides an empty value * Provides an empty value

View File

@@ -33,7 +33,7 @@ abstract class BaseType
*/ */
public function getAll() public function getAll()
{ {
if ($this->all === null) { if (null === $this->all) {
$this->all = Reflection::getConstants($this); $this->all = Reflection::getConstants($this);
} }

View File

@@ -415,7 +415,7 @@ class Arrays
* var autoGeneratedVariable = new Array(...);autoGeneratedVariable[0] = new Array(...); * var autoGeneratedVariable = new Array(...);autoGeneratedVariable[0] = new Array(...);
* autoGeneratedVariable[1] = new Array(...); * autoGeneratedVariable[1] = new Array(...);
*/ */
if ($counter === 1) { if (1 === $counter) {
$effect .= "\n"; $effect .= "\n";
} }
@@ -758,7 +758,7 @@ class Arrays
foreach ($exploded as $item) { foreach ($exploded as $item) {
$exploded2 = explode($valuesKeysSeparator, $item); $exploded2 = explode($valuesKeysSeparator, $item);
if (count($exploded2) == 2) { if (2 == count($exploded2)) {
$key = trim($exploded2[0]); $key = trim($exploded2[0]);
$value = trim($exploded2[1]); $value = trim($exploded2[1]);
@@ -1124,7 +1124,7 @@ class Arrays
if (!empty($array)) { if (!empty($array)) {
$childPosition = 1; $childPosition = 1;
if ($startPosition !== null) { if (null !== $startPosition) {
$array[$keyName] = $startPosition; $array[$keyName] = $startPosition;
} }
@@ -1316,7 +1316,7 @@ class Arrays
* *
* If one of the above is true, not all elements of given array are empty * If one of the above is true, not all elements of given array are empty
*/ */
if ((!is_array($element) && $strictNull && $element !== null) || !empty($element)) { if ((!is_array($element) && $strictNull && null !== $element) || !empty($element)) {
return false; return false;
} }
} }
@@ -1353,7 +1353,7 @@ class Arrays
* Values should be compared only and both arrays are one-dimensional? * Values should be compared only and both arrays are one-dimensional?
* Let's find difference by using simple function * Let's find difference by using simple function
*/ */
if ($valuesOnly && self::getDimensionsCount($array1) == 1 && self::getDimensionsCount($array2) == 1) { if ($valuesOnly && 1 == self::getDimensionsCount($array1) && 1 == self::getDimensionsCount($array2)) {
return array_diff($array1, $array2); return array_diff($array1, $array2);
} }
@@ -1381,7 +1381,7 @@ class Arrays
} }
} }
if ($difference !== null) { if (null !== $difference) {
$effect[] = $difference; $effect[] = $difference;
} }
} else { } else {
@@ -1472,7 +1472,7 @@ class Arrays
* Start index not provided? * Start index not provided?
* Let's look for the first index / key of given array * Let's look for the first index / key of given array
*/ */
if ($startIndex === null) { if (null === $startIndex) {
$startIndex = self::getFirstKey($array); $startIndex = self::getFirstKey($array);
} }
@@ -1617,7 +1617,7 @@ class Arrays
* Index of element or of element's key is unknown? * Index of element or of element's key is unknown?
* Probably the element does not exist in given array, so... nothing to do * Probably the element does not exist in given array, so... nothing to do
*/ */
if ($elementKey === null || $indexOfKey === null) { if (null === $elementKey || null === $indexOfKey) {
return null; return null;
} }

View File

@@ -59,7 +59,7 @@ class Composer
* Unknown data from the composer.json file or there is no node with given name? * Unknown data from the composer.json file or there is no node with given name?
* Nothing to do * Nothing to do
*/ */
if ($data === null || !isset($data->{$nodeName})) { if (null === $data || !isset($data->{$nodeName})) {
return null; return null;
} }

View File

@@ -129,10 +129,10 @@ class Date
$dateStart = new DateTime(); $dateStart = new DateTime();
$dateEnd = new DateTime(); $dateEnd = new DateTime();
if ($period == DatePeriod::LAST_YEAR || $period == DatePeriod::NEXT_YEAR) { if (DatePeriod::LAST_YEAR == $period || DatePeriod::NEXT_YEAR == $period) {
$yearDifference = 1; $yearDifference = 1;
if ($period == DatePeriod::LAST_YEAR) { if (DatePeriod::LAST_YEAR == $period) {
$yearDifference *= -1; $yearDifference *= -1;
} }
@@ -148,7 +148,7 @@ class Date
break; break;
} }
if ($dateStart !== null && $dateEnd !== null) { if (null !== $dateStart && null !== $dateEnd) {
$dateStart->setTime(0, 0, 0); $dateStart->setTime(0, 0, 0);
$dateEnd->setTime(23, 59, 59); $dateEnd->setTime(23, 59, 59);
@@ -311,7 +311,7 @@ class Date
$encoding = mb_detect_encoding($name); $encoding = mb_detect_encoding($name);
if ($encoding === false) { if (false === $encoding) {
$name = mb_convert_encoding($name, 'UTF-8', 'ISO-8859-2'); $name = mb_convert_encoding($name, 'UTF-8', 'ISO-8859-2');
} }
@@ -378,46 +378,46 @@ class Date
self::DATE_DIFFERENCE_UNIT_MINUTES, self::DATE_DIFFERENCE_UNIT_MINUTES,
]; ];
if ($differenceUnit === null || $differenceUnit == self::DATE_DIFFERENCE_UNIT_YEARS) { if (null === $differenceUnit || self::DATE_DIFFERENCE_UNIT_YEARS == $differenceUnit) {
$diff = $dateEnd->diff($dateStart); $diff = $dateEnd->diff($dateStart);
/* /*
* Difference between dates in years should be returned only? * Difference between dates in years should be returned only?
*/ */
if ($differenceUnit == self::DATE_DIFFERENCE_UNIT_YEARS) { if (self::DATE_DIFFERENCE_UNIT_YEARS == $differenceUnit) {
return $diff->y; return $diff->y;
} }
$difference[self::DATE_DIFFERENCE_UNIT_YEARS] = $diff->y; $difference[self::DATE_DIFFERENCE_UNIT_YEARS] = $diff->y;
} }
if ($differenceUnit === null || $differenceUnit == self::DATE_DIFFERENCE_UNIT_MONTHS) { if (null === $differenceUnit || self::DATE_DIFFERENCE_UNIT_MONTHS == $differenceUnit) {
$diff = $dateEnd->diff($dateStart); $diff = $dateEnd->diff($dateStart);
/* /*
* Difference between dates in months should be returned only? * Difference between dates in months should be returned only?
*/ */
if ($differenceUnit == self::DATE_DIFFERENCE_UNIT_MONTHS) { if (self::DATE_DIFFERENCE_UNIT_MONTHS == $differenceUnit) {
return $diff->m; return $diff->m;
} }
$difference[self::DATE_DIFFERENCE_UNIT_MONTHS] = $diff->m; $difference[self::DATE_DIFFERENCE_UNIT_MONTHS] = $diff->m;
} }
if ($differenceUnit === null || in_array($differenceUnit, $relatedUnits)) { if (null === $differenceUnit || in_array($differenceUnit, $relatedUnits)) {
$days = (int)floor($dateDiff / $daySeconds); $days = (int)floor($dateDiff / $daySeconds);
/* /*
* Difference between dates in days should be returned only? * Difference between dates in days should be returned only?
*/ */
if ($differenceUnit == self::DATE_DIFFERENCE_UNIT_DAYS) { if (self::DATE_DIFFERENCE_UNIT_DAYS == $differenceUnit) {
return $days; return $days;
} }
/* /*
* All units should be returned? * All units should be returned?
*/ */
if ($differenceUnit === null) { if (null === $differenceUnit) {
$difference[self::DATE_DIFFERENCE_UNIT_DAYS] = $days; $difference[self::DATE_DIFFERENCE_UNIT_DAYS] = $days;
} }
@@ -427,20 +427,20 @@ class Date
$daysInSeconds = $days * $daySeconds; $daysInSeconds = $days * $daySeconds;
} }
if ($differenceUnit === null || in_array($differenceUnit, $relatedUnits)) { if (null === $differenceUnit || in_array($differenceUnit, $relatedUnits)) {
$hours = (int)floor(($dateDiff - $daysInSeconds) / $hourSeconds); $hours = (int)floor(($dateDiff - $daysInSeconds) / $hourSeconds);
/* /*
* Difference between dates in hours should be returned only? * Difference between dates in hours should be returned only?
*/ */
if ($differenceUnit == self::DATE_DIFFERENCE_UNIT_HOURS) { if (self::DATE_DIFFERENCE_UNIT_HOURS == $differenceUnit) {
return $hours; return $hours;
} }
/* /*
* All units should be returned? * All units should be returned?
*/ */
if ($differenceUnit === null) { if (null === $differenceUnit) {
$difference[self::DATE_DIFFERENCE_UNIT_HOURS] = $hours; $difference[self::DATE_DIFFERENCE_UNIT_HOURS] = $hours;
} }
@@ -450,13 +450,13 @@ class Date
$hoursInSeconds = $hours * $hourSeconds; $hoursInSeconds = $hours * $hourSeconds;
} }
if ($differenceUnit === null || $differenceUnit == self::DATE_DIFFERENCE_UNIT_MINUTES) { if (null === $differenceUnit || self::DATE_DIFFERENCE_UNIT_MINUTES == $differenceUnit) {
$minutes = (int)floor(($dateDiff - $daysInSeconds - $hoursInSeconds) / 60); $minutes = (int)floor(($dateDiff - $daysInSeconds - $hoursInSeconds) / 60);
/* /*
* Difference between dates in minutes should be returned only? * Difference between dates in minutes should be returned only?
*/ */
if ($differenceUnit == self::DATE_DIFFERENCE_UNIT_MINUTES) { if (self::DATE_DIFFERENCE_UNIT_MINUTES == $differenceUnit) {
return $minutes; return $minutes;
} }
@@ -524,7 +524,7 @@ class Date
*/ */
public static function getRandomDate(DateTime $startDate = null, $start = 1, $end = 100, $intervalTemplate = 'P%sD') public static function getRandomDate(DateTime $startDate = null, $start = 1, $end = 100, $intervalTemplate = 'P%sD')
{ {
if ($startDate === null) { if (null === $startDate) {
$startDate = new DateTime(); $startDate = new DateTime();
} }
@@ -590,7 +590,7 @@ class Date
*/ */
$dateFromFormat = DateTime::createFromFormat($dateFormat, $value); $dateFromFormat = DateTime::createFromFormat($dateFormat, $value);
if ($dateFromFormat === false) { if (false === $dateFromFormat) {
/* /*
* Nothing to do more, because: * Nothing to do more, because:
* a) instance of the DateTime was created * a) instance of the DateTime was created

View File

@@ -140,7 +140,7 @@ class DatePeriod
/* /*
* Unknown date or format is invalid? * Unknown date or format is invalid?
*/ */
if ($date === null || !Date::isValidDateFormat($format)) { if (null === $date || !Date::isValidDateFormat($format)) {
return ''; return '';
} }

View File

@@ -65,7 +65,7 @@ class Miscellaneous
if (!empty($directoryContent)) { if (!empty($directoryContent)) {
foreach ($directoryContent as $fileName) { foreach ($directoryContent as $fileName) {
if ($fileName != '.' && $fileName != '..') { if ('.' != $fileName && '..' != $fileName) {
$content = null; $content = null;
if (!empty($startFileName) && !$startFileFound) { if (!empty($startFileName) && !$startFileFound) {
@@ -80,7 +80,7 @@ class Miscellaneous
$content = self::getDirectoryContent($directoryPath . $fileName, true, $maxFilesCount - $count); $content = self::getDirectoryContent($directoryPath . $fileName, true, $maxFilesCount - $count);
} }
if ($content !== null) { if (null !== $content) {
$files[$fileName] = $content; $files[$fileName] = $content;
if (!empty($maxFilesCount)) { if (!empty($maxFilesCount)) {
@@ -365,7 +365,7 @@ class Miscellaneous
* Oops, cannot instantiate converter * Oops, cannot instantiate converter
* Nothing to do * Nothing to do
*/ */
if ($converter === null) { if (null === $converter) {
return ''; return '';
} }
@@ -460,7 +460,7 @@ class Miscellaneous
* Value to find is neither a string nor an array OR it's an empty string? * Value to find is neither a string nor an array OR it's an empty string?
* Nothing to do * Nothing to do
*/ */
if ((!$searchIsString && !$searchIsArray) || ($searchIsString && strlen($search) == 0)) { if ((!$searchIsString && !$searchIsArray) || ($searchIsString && 0 == strlen($search))) {
return $effect; return $effect;
} }
@@ -612,7 +612,7 @@ class Miscellaneous
$effect = mb_substr($text, 0, $maxLength, 'utf-8'); $effect = mb_substr($text, 0, $maxLength, 'utf-8');
$lastSpacePosition = mb_strrpos($effect, ' ', 'utf-8'); $lastSpacePosition = mb_strrpos($effect, ' ', 'utf-8');
if ($lastSpacePosition !== false) { if (false !== $lastSpacePosition) {
$effect = mb_substr($effect, 0, $lastSpacePosition, 'utf-8'); $effect = mb_substr($effect, 0, $lastSpacePosition, 'utf-8');
} }
@@ -730,7 +730,7 @@ class Miscellaneous
} }
foreach (scandir($directoryPath) as $item) { foreach (scandir($directoryPath) as $item) {
if ($item == '.' || $item == '..') { if ('.' == $item || '..' == $item) {
continue; continue;
} }
@@ -776,7 +776,7 @@ class Miscellaneous
foreach ($members as $key => $value) { foreach ($members as $key => $value) {
$value = mb_strtolower($value); $value = mb_strtolower($value);
if ($key == 0) { if (0 == $key) {
$effect .= self::lowercaseFirst($value); $effect .= self::lowercaseFirst($value);
} else { } else {
$effect .= self::uppercaseFirst($value); $effect .= self::uppercaseFirst($value);
@@ -812,7 +812,7 @@ class Miscellaneous
if ($restLowercase) { if ($restLowercase) {
$effect = mb_strtolower($effect); $effect = mb_strtolower($effect);
} elseif ($restLowercase === false) { } elseif (false === $restLowercase) {
$effect = mb_strtoupper($effect); $effect = mb_strtoupper($effect);
} }
@@ -850,7 +850,7 @@ class Miscellaneous
if ($restLowercase) { if ($restLowercase) {
$effect = mb_strtolower($effect); $effect = mb_strtolower($effect);
} elseif ($restLowercase === false) { } elseif (false === $restLowercase) {
$effect = mb_strtoupper($effect); $effect = mb_strtoupper($effect);
} }
@@ -1153,7 +1153,7 @@ class Miscellaneous
{ {
$value = filter_input($globalSourceType, $variableName); $value = filter_input($globalSourceType, $variableName);
if ($value === null) { if (null === $value) {
$globalSource = null; $globalSource = null;
switch ($globalSourceType) { switch ($globalSourceType) {
@@ -1178,7 +1178,7 @@ class Miscellaneous
break; break;
} }
if ($globalSource !== null && isset($globalSource[$variableName])) { if (null !== $globalSource && isset($globalSource[$variableName])) {
$value = $globalSource[$variableName]; $value = $globalSource[$variableName];
if (!ini_get('magic_quotes_gpc')) { if (!ini_get('magic_quotes_gpc')) {
@@ -1232,7 +1232,7 @@ class Miscellaneous
/* /*
* First line is only HTTP status and is unneeded so skip it * First line is only HTTP status and is unneeded so skip it
*/ */
if ($i === 0) { if (0 === $i) {
continue; continue;
} }
@@ -1242,7 +1242,7 @@ class Miscellaneous
/* /*
* If the header is a "set-cookie" let's save it to "cookies" array * If the header is a "set-cookie" let's save it to "cookies" array
*/ */
if ($key === 'Set-Cookie') { if ('Set-Cookie' === $key) {
$cookieParameters = explode(';', $value); $cookieParameters = explode(';', $value);
$name = ''; $name = '';
@@ -1260,7 +1260,7 @@ class Miscellaneous
* First parameter will be always a cookie name and it's value. It is not needed to run * First parameter will be always a cookie name and it's value. It is not needed to run
* further actions for them, so save the values and move to next parameter. * further actions for them, so save the values and move to next parameter.
*/ */
if ($j === 0) { if (0 === $j) {
$name = trim($param[0]); $name = trim($param[0]);
$value = trim($param[1]); $value = trim($param[1]);
continue; continue;
@@ -1416,7 +1416,7 @@ class Miscellaneous
if ($asHexadecimal) { if ($asHexadecimal) {
$hexadecimal = dechex($colorComponent); $hexadecimal = dechex($colorComponent);
if (strlen($hexadecimal) == 1) { if (1 == strlen($hexadecimal)) {
return sprintf('0%s', $hexadecimal, $hexadecimal); return sprintf('0%s', $hexadecimal, $hexadecimal);
} }

View File

@@ -108,7 +108,7 @@ class QueryBuilderUtility
$compareOperator = '='; $compareOperator = '=';
if (is_array($value) && !empty($value)) { if (is_array($value) && !empty($value)) {
if (count($value) == 2) { if (2 == count($value)) {
$compareOperator = $value[1]; $compareOperator = $value[1];
} }
@@ -117,7 +117,7 @@ class QueryBuilderUtility
$predicate = sprintf('%s.%s %s :%s', $alias, $column, $compareOperator, $column); $predicate = sprintf('%s.%s %s :%s', $alias, $column, $compareOperator, $column);
if ($value === null) { if (null === $value) {
$predicate = $queryBuilder->expr()->isNull(sprintf('%s.%s', $alias, $column)); $predicate = $queryBuilder->expr()->isNull(sprintf('%s.%s', $alias, $column));
unset($criteria[$column]); unset($criteria[$column]);
} else { } else {

View File

@@ -201,7 +201,7 @@ class Reflection
* Krzysztof Niziol <krzysztof.niziol@meritoo.pl> * Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* 2016-11-07 * 2016-11-07
*/ */
if ($object !== null) { if (null !== $object) {
unset($exploded[0]); unset($exploded[0]);
$property = implode('.', $exploded); $property = implode('.', $exploded);
@@ -246,7 +246,7 @@ class Reflection
} }
} }
if (!$valueFound && $reflectionProperty !== null) { if (!$valueFound && null !== $reflectionProperty) {
/* /*
* Oops, we have got exception. * Oops, we have got exception.
* *
@@ -285,7 +285,7 @@ class Reflection
foreach ($objects as $entity) { foreach ($objects as $entity) {
$value = self::getPropertyValue($entity, $property, $force); $value = self::getPropertyValue($entity, $property, $force);
if ($value !== null) { if (null !== $value) {
$values[] = $value; $values[] = $value;
} }
} }
@@ -345,7 +345,7 @@ class Reflection
if ($withoutNamespace) { if ($withoutNamespace) {
$classOnly = Miscellaneous::getLastElementOfString($name, '\\'); $classOnly = Miscellaneous::getLastElementOfString($name, '\\');
if ($classOnly !== null) { if (null !== $classOnly) {
$name = $classOnly; $name = $classOnly;
} }
@@ -427,7 +427,7 @@ class Reflection
$className = self::getClassName($source); $className = self::getClassName($source);
$reflection = new ReflectionClass($className); $reflection = new ReflectionClass($className);
if ($filter === null) { if (null === $filter) {
$filter = ReflectionProperty::IS_PRIVATE $filter = ReflectionProperty::IS_PRIVATE
+ ReflectionProperty::IS_PROTECTED + ReflectionProperty::IS_PROTECTED
+ ReflectionProperty::IS_PUBLIC + ReflectionProperty::IS_PUBLIC
@@ -477,7 +477,7 @@ class Reflection
/* /*
* Oops, cannot resolve class * Oops, cannot resolve class
*/ */
if ($className === null) { if (null === $className) {
throw new CannotResolveClassNameException($class); throw new CannotResolveClassNameException($class);
} }
@@ -603,7 +603,7 @@ class Reflection
if (!$uses && $verifyParents) { if (!$uses && $verifyParents) {
$parentClassName = self::getParentClassName($className); $parentClassName = self::getParentClassName($className);
if ($parentClassName !== null) { if (null !== $parentClassName) {
return self::usesTrait($parentClassName, $trait, true); return self::usesTrait($parentClassName, $trait, true);
} }
} }
@@ -624,7 +624,7 @@ class Reflection
$reflection = new ReflectionClass($className); $reflection = new ReflectionClass($className);
$parentClass = $reflection->getParentClass(); $parentClass = $reflection->getParentClass();
if ($parentClass === null || $parentClass === false) { if (null === $parentClass || false === $parentClass) {
return null; return null;
} }

View File

@@ -84,7 +84,7 @@ class Regex
$taxid = preg_replace('/[\s-]/', '', $taxidString); $taxid = preg_replace('/[\s-]/', '', $taxidString);
$sum = 0; $sum = 0;
if (strlen($taxid) == 10 && is_numeric($taxid)) { if (10 == strlen($taxid) && is_numeric($taxid)) {
for ($x = 0; $x <= 8; ++$x) { for ($x = 0; $x <= 8; ++$x) {
$sum += $taxid[$x] * $weights[$x]; $sum += $taxid[$x] * $weights[$x];
} }
@@ -185,9 +185,9 @@ class Regex
$pattern = '|' . $filterExpression . '|'; $pattern = '|' . $filterExpression . '|';
$matchesCount = preg_match($pattern, $value, $matches); $matchesCount = preg_match($pattern, $value, $matches);
$remove = $matchesCount == 0; $remove = 0 == $matchesCount;
} else { } else {
if ($value == '') { if ('' == $value) {
$value = '\'\''; $value = '\'\'';
} elseif (is_string($value)) { } elseif (is_string($value)) {
$value = '\'' . $value . '\''; $value = '\'' . $value . '\'';
@@ -431,7 +431,7 @@ class Regex
public static function startsWith($string, $beginning) public static function startsWith($string, $beginning)
{ {
if (!empty($string) && !empty($beginning)) { if (!empty($string) && !empty($beginning)) {
if (strlen($beginning) == 1 && !self::isLetterOrDigit($beginning)) { if (1 == strlen($beginning) && !self::isLetterOrDigit($beginning)) {
$beginning = '\\' . $beginning; $beginning = '\\' . $beginning;
} }
@@ -452,7 +452,7 @@ class Regex
*/ */
public static function endsWith($string, $ending) public static function endsWith($string, $ending)
{ {
if (strlen($ending) == 1 && !self::isLetterOrDigit($ending)) { if (1 == strlen($ending) && !self::isLetterOrDigit($ending)) {
$ending = '\\' . $ending; $ending = '\\' . $ending;
} }
@@ -537,7 +537,7 @@ class Regex
*/ */
public static function contains($haystack, $needle) public static function contains($haystack, $needle)
{ {
if (strlen($needle) == 1 && !self::isLetterOrDigit($needle)) { if (1 == strlen($needle) && !self::isLetterOrDigit($needle)) {
$needle = '\\' . $needle; $needle = '\\' . $needle;
} }
@@ -653,7 +653,7 @@ class Regex
} }
$modulo = $sum % 11; $modulo = $sum % 11;
$numberControl = ($modulo == 10) ? 0 : $modulo; $numberControl = (10 == $modulo) ? 0 : $modulo;
return $numberControl == $nip[9]; return $numberControl == $nip[9];
} }
@@ -698,10 +698,10 @@ class Regex
$color = Miscellaneous::replace($color, '/#/', ''); $color = Miscellaneous::replace($color, '/#/', '');
$length = strlen($color); $length = strlen($color);
if ($length === 3) { if (3 === $length) {
$color = Miscellaneous::replace($color, '/(.)(.)(.)/', '$1$1$2$2$3$3'); $color = Miscellaneous::replace($color, '/(.)(.)(.)/', '$1$1$2$2$3$3');
} else { } else {
if ($length !== 6) { if (6 !== $length) {
if ($throwException) { if ($throwException) {
throw new IncorrectColorHexLengthException($color); throw new IncorrectColorHexLengthException($color);
} }

View File

@@ -31,14 +31,14 @@ class Repository
{ {
$position = self::getExtremePosition($items, $asLast); $position = self::getExtremePosition($items, $asLast);
if ($position === null && $force) { if (null === $position && $force) {
$position = 0; $position = 0;
} }
if ($position !== null && !empty($items)) { if (null !== $position && !empty($items)) {
foreach ($items as $item) { foreach ($items as $item) {
if (method_exists($item, 'getPosition')) { if (method_exists($item, 'getPosition')) {
if ($item->getPosition() === null) { if (null === $item->getPosition()) {
if ($asLast) { if ($asLast) {
++$position; ++$position;
} else { } else {

View File

@@ -40,7 +40,7 @@ class Xml
$query = $path->query('/*/*'); $query = $path->query('/*/*');
$nodesCount = $query->length; $nodesCount = $query->length;
if ($nodesCount == 0) { if (0 == $nodesCount) {
return $element1; return $element1;
} }

View File

@@ -10,7 +10,7 @@ namespace Meritoo\Common\Test\Exception\Base;
use Meritoo\Common\Exception\Base\UnknownTypeException; use Meritoo\Common\Exception\Base\UnknownTypeException;
use Meritoo\Common\Type\Base\BaseType; use Meritoo\Common\Type\Base\BaseType;
use PHPUnit_Framework_TestCase; use PHPUnit\Framework\TestCase;
/** /**
* Tests of the exception used while type of something is unknown * Tests of the exception used while type of something is unknown
@@ -18,7 +18,7 @@ use PHPUnit_Framework_TestCase;
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl> * @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl * @copyright Meritoo.pl
*/ */
class UnknownTypeExceptionTest extends PHPUnit_Framework_TestCase class UnknownTypeExceptionTest extends TestCase
{ {
public function testWithoutException() public function testWithoutException()
{ {

View File

@@ -10,7 +10,7 @@ namespace Meritoo\Common\Test\Type\Base;
use Generator; use Generator;
use Meritoo\Common\Type\Base\BaseType; use Meritoo\Common\Type\Base\BaseType;
use PHPUnit_Framework_TestCase; use PHPUnit\Framework\TestCase;
/** /**
* Tests of the base / abstract type of something * Tests of the base / abstract type of something
@@ -18,7 +18,7 @@ use PHPUnit_Framework_TestCase;
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl> * @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl * @copyright Meritoo.pl
*/ */
class BaseTypeTest extends PHPUnit_Framework_TestCase class BaseTypeTest extends TestCase
{ {
/** /**
* @param BaseType $type Type of something * @param BaseType $type Type of something

View File

@@ -9,7 +9,7 @@
namespace Meritoo\Common\Test\Utilities; namespace Meritoo\Common\Test\Utilities;
use Meritoo\Common\Utilities\Arrays; use Meritoo\Common\Utilities\Arrays;
use PHPUnit_Framework_TestCase; use PHPUnit\Framework\TestCase;
/** /**
* Tests of the useful arrays methods * Tests of the useful arrays methods
@@ -17,7 +17,7 @@ use PHPUnit_Framework_TestCase;
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl> * @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl * @copyright Meritoo.pl
*/ */
class ArraysTest extends PHPUnit_Framework_TestCase class ArraysTest extends TestCase
{ {
private $simpleArray; private $simpleArray;
private $simpleArrayWithKeys; private $simpleArrayWithKeys;

View File

@@ -9,7 +9,7 @@
namespace Meritoo\Common\Test\Utilities; namespace Meritoo\Common\Test\Utilities;
use Meritoo\Common\Utilities\Bundle; use Meritoo\Common\Utilities\Bundle;
use PHPUnit_Framework_TestCase; use PHPUnit\Framework\TestCase;
/** /**
* Tests of the useful methods for bundle * Tests of the useful methods for bundle
@@ -17,7 +17,7 @@ use PHPUnit_Framework_TestCase;
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl> * @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl * @copyright Meritoo.pl
*/ */
class BundleTest extends PHPUnit_Framework_TestCase class BundleTest extends TestCase
{ {
public function testGetBundleViewPathEmptyPathAndBundle() public function testGetBundleViewPathEmptyPathAndBundle()
{ {

View File

@@ -8,16 +8,17 @@
namespace Meritoo\Common\Utilities; namespace Meritoo\Common\Utilities;
use PHPUnit\Framework\TestCase;
/** /**
* Tests of the useful regular expressions methods * Tests of the useful regular expressions methods
* *
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl> * @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl * @copyright Meritoo.pl
*/ */
class RegexTest extends \PHPUnit_Framework_TestCase class RegexTest extends TestCase
{ {
private $simpleText; private $simpleText;
private $camelCaseText; private $camelCaseText;
public function testGetCamelCaseParts() public function testGetCamelCaseParts()

View File

@@ -9,7 +9,7 @@
namespace Meritoo\Common\Test\Utilities; namespace Meritoo\Common\Test\Utilities;
use Meritoo\Common\Utilities\Xml; use Meritoo\Common\Utilities\Xml;
use PHPUnit_Framework_TestCase; use PHPUnit\Framework\TestCase;
use SimpleXMLElement; use SimpleXMLElement;
/** /**
@@ -18,7 +18,7 @@ use SimpleXMLElement;
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl> * @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl * @copyright Meritoo.pl
*/ */
class XmlTest extends PHPUnit_Framework_TestCase class XmlTest extends TestCase
{ {
private $simpleXml; private $simpleXml;
private $advancedXml; private $advancedXml;