mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 09:31:51 +01:00
Refactor & fix coding standard
This commit is contained in:
@@ -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.3",
|
"version": "0.0.4",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Meritoo.pl",
|
"name": "Meritoo.pl",
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
<?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\Date;
|
|
||||||
|
|
||||||
use Exception;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An exception used while given part of date is incorrect, e.g. value of year is incorrect
|
|
||||||
*
|
|
||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
|
||||||
* @copyright Meritoo.pl
|
|
||||||
*/
|
|
||||||
class IncorrectDatePartException extends Exception
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Class constructor
|
|
||||||
*
|
|
||||||
* @param string $value Incorrect value
|
|
||||||
* @param string $datePart Type of date part, e.g. "year". One of \Meritoo\Common\Type\DatePartType class constants.
|
|
||||||
*/
|
|
||||||
public function __construct($value, $datePart)
|
|
||||||
{
|
|
||||||
$message = sprintf('Value of %s \'%s\' is incorrect. Is there everything ok?', $datePart, $value);
|
|
||||||
parent::__construct($message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?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\Date;
|
||||||
|
|
||||||
|
use Meritoo\Common\Exception\Base\UnknownTypeException;
|
||||||
|
use Meritoo\Common\Type\DatePartType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An exception used while type of date part, e.g. "year", is unknown
|
||||||
|
*
|
||||||
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
|
* @copyright Meritoo.pl
|
||||||
|
*/
|
||||||
|
class UnknownDatePartTypeException extends UnknownTypeException
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Class constructor
|
||||||
|
*
|
||||||
|
* @param string $unknownDatePart Type of date part, e.g. "year". One of DatePartType class constants.
|
||||||
|
* @param string $value Incorrect value
|
||||||
|
*/
|
||||||
|
public function __construct($unknownDatePart, $value)
|
||||||
|
{
|
||||||
|
parent::__construct($unknownDatePart, new DatePartType(), sprintf('date part (with value %s)', $value));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@ namespace Meritoo\Common\Utilities;
|
|||||||
|
|
||||||
use DateInterval;
|
use DateInterval;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Meritoo\Common\Exception\Date\IncorrectDatePartException;
|
use Meritoo\Common\Exception\Date\UnknownDatePartTypeException;
|
||||||
use Meritoo\Common\Type\DatePartType;
|
use Meritoo\Common\Type\DatePartType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -231,7 +231,7 @@ class Date
|
|||||||
* @param int $day The day value
|
* @param int $day The day value
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
* @throws IncorrectDatePartException
|
* @throws UnknownDatePartTypeException
|
||||||
*/
|
*/
|
||||||
public static function getDayOfWeek($year, $month, $day)
|
public static function getDayOfWeek($year, $month, $day)
|
||||||
{
|
{
|
||||||
@@ -243,21 +243,21 @@ class Date
|
|||||||
* Oops, incorrect year
|
* Oops, incorrect year
|
||||||
*/
|
*/
|
||||||
if ($year <= 0) {
|
if ($year <= 0) {
|
||||||
throw new IncorrectDatePartException($year, DatePartType::YEAR);
|
throw new UnknownDatePartTypeException(DatePartType::YEAR, $year);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Oops, incorrect month
|
* Oops, incorrect month
|
||||||
*/
|
*/
|
||||||
if ($month < 1 || $month > 12) {
|
if ($month < 1 || $month > 12) {
|
||||||
throw new IncorrectDatePartException($month, DatePartType::MONTH);
|
throw new UnknownDatePartTypeException(DatePartType::MONTH, $month);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Oops, incorrect day
|
* Oops, incorrect day
|
||||||
*/
|
*/
|
||||||
if ($day < 1 || $day > 31) {
|
if ($day < 1 || $day > 31) {
|
||||||
throw new IncorrectDatePartException($day, DatePartType::DAY);
|
throw new UnknownDatePartTypeException(DatePartType::DAY, $day);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($month < 3) {
|
if ($month < 3) {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ namespace Meritoo\Common\Utilities;
|
|||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Generator;
|
use Generator;
|
||||||
|
use PHPUnit_Framework_TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test case with common methods and data providers
|
* Test case with common methods and data providers
|
||||||
@@ -17,7 +18,7 @@ use Generator;
|
|||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class TestCase extends \PHPUnit_Framework_TestCase
|
class TestCase extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Provides an empty value
|
* Provides an empty value
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ namespace Meritoo\Common\Tests\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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests of the exception used while type of something is unknown
|
* Tests of the exception used while type of something is unknown
|
||||||
@@ -17,7 +18,7 @@ use Meritoo\Common\Type\Base\BaseType;
|
|||||||
* @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 PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testWithoutException()
|
public function testWithoutException()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ namespace Meritoo\Common\Tests\Type\Base;
|
|||||||
|
|
||||||
use Generator;
|
use Generator;
|
||||||
use Meritoo\Common\Type\Base\BaseType;
|
use Meritoo\Common\Type\Base\BaseType;
|
||||||
|
use PHPUnit_Framework_TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests of the base / abstract type of something
|
* Tests of the base / abstract type of something
|
||||||
@@ -17,7 +18,7 @@ use Meritoo\Common\Type\Base\BaseType;
|
|||||||
* @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 PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param BaseType $type Type of something
|
* @param BaseType $type Type of something
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ namespace Meritoo\Common\Tests\Type;
|
|||||||
|
|
||||||
use Generator;
|
use Generator;
|
||||||
use Meritoo\Common\Type\DatePartType;
|
use Meritoo\Common\Type\DatePartType;
|
||||||
|
use PHPUnit_Framework_TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests of the type of date part, e.g. "year"
|
* Tests of the type of date part, e.g. "year"
|
||||||
@@ -17,7 +18,7 @@ use Meritoo\Common\Type\DatePartType;
|
|||||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||||
* @copyright Meritoo.pl
|
* @copyright Meritoo.pl
|
||||||
*/
|
*/
|
||||||
class DatePartTypeTest extends \PHPUnit_Framework_TestCase
|
class DatePartTypeTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testGetAll()
|
public function testGetAll()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
namespace Meritoo\Common\Tests\Utilities;
|
namespace Meritoo\Common\Tests\Utilities;
|
||||||
|
|
||||||
use Meritoo\Common\Utilities\Arrays;
|
use Meritoo\Common\Utilities\Arrays;
|
||||||
|
use PHPUnit_Framework_TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests of the useful arrays methods
|
* Tests of the useful arrays methods
|
||||||
@@ -16,7 +17,7 @@ use Meritoo\Common\Utilities\Arrays;
|
|||||||
* @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 PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
private $simpleArray;
|
private $simpleArray;
|
||||||
private $simpleArrayWithKeys;
|
private $simpleArrayWithKeys;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
namespace Meritoo\Common\Tests\Utilities;
|
namespace Meritoo\Common\Tests\Utilities;
|
||||||
|
|
||||||
use Meritoo\Common\Utilities\Bundle;
|
use Meritoo\Common\Utilities\Bundle;
|
||||||
|
use PHPUnit_Framework_TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests of the useful methods for bundle
|
* Tests of the useful methods for bundle
|
||||||
@@ -16,7 +17,7 @@ use Meritoo\Common\Utilities\Bundle;
|
|||||||
* @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 PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testGetBundleViewPathEmptyPathAndBundle()
|
public function testGetBundleViewPathEmptyPathAndBundle()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace Meritoo\Common\Tests\Utilities;
|
|||||||
use DateInterval;
|
use DateInterval;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Generator;
|
use Generator;
|
||||||
use Meritoo\Common\Exception\Date\IncorrectDatePartException;
|
use Meritoo\Common\Exception\Date\UnknownDatePartTypeException;
|
||||||
use Meritoo\Common\Utilities\Date;
|
use Meritoo\Common\Utilities\Date;
|
||||||
use Meritoo\Common\Utilities\TestCase;
|
use Meritoo\Common\Utilities\TestCase;
|
||||||
|
|
||||||
@@ -218,7 +218,7 @@ class DateTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testGetDayOfWeekIncorrectValues($year, $month, $day)
|
public function testGetDayOfWeekIncorrectValues($year, $month, $day)
|
||||||
{
|
{
|
||||||
$this->expectException(IncorrectDatePartException::class);
|
$this->expectException(UnknownDatePartTypeException::class);
|
||||||
self::assertEmpty(Date::getDayOfWeek($year, $month, $day));
|
self::assertEmpty(Date::getDayOfWeek($year, $month, $day));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
namespace Meritoo\Common\Tests\Utilities;
|
namespace Meritoo\Common\Tests\Utilities;
|
||||||
|
|
||||||
use Meritoo\Common\Utilities\Xml;
|
use Meritoo\Common\Utilities\Xml;
|
||||||
|
use PHPUnit_Framework_TestCase;
|
||||||
use SimpleXMLElement;
|
use SimpleXMLElement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -17,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 PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
private $simpleXml;
|
private $simpleXml;
|
||||||
private $advancedXml;
|
private $advancedXml;
|
||||||
|
|||||||
Reference in New Issue
Block a user