mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 09:31:51 +01:00
Improve coding standard
This commit is contained in:
@@ -628,10 +628,10 @@ class Miscellaneous
|
|||||||
* Breaks long text
|
* Breaks long text
|
||||||
*
|
*
|
||||||
* @param string $text The text to check and break
|
* @param string $text The text to check and break
|
||||||
* @param int $perLine (optional) Characters count per line
|
* @param int $perLine (optional) Characters count per line. Default: 100.
|
||||||
* @param string $separator (optional) Separator that is placed beetwen lines
|
* @param string $separator (optional) Separator that is placed between lines. Default: "<br>".
|
||||||
* @param string $encoding (optional) Character encoding. Used by mb_substr().
|
* @param string $encoding (optional) Character encoding. Used by mb_substr(). Default: "UTF-8".
|
||||||
* @param int $proportionalAberration (optional) Proportional aberration for chars (percent value)
|
* @param int $proportionalAberration (optional) Proportional aberration for chars (percent value). Default: 20.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function breakLongText(
|
public static function breakLongText(
|
||||||
@@ -718,15 +718,23 @@ class Miscellaneous
|
|||||||
*
|
*
|
||||||
* @param string $directoryPath Directory path
|
* @param string $directoryPath Directory path
|
||||||
* @param bool $contentOnly (optional) If is set to true, only content of the directory is removed, not
|
* @param bool $contentOnly (optional) If is set to true, only content of the directory is removed, not
|
||||||
* directory. Otherwise - directory is removed too.
|
* directory itself. Otherwise - directory is removed too (default behaviour).
|
||||||
* @return bool
|
* @return bool|null
|
||||||
*/
|
*/
|
||||||
public static function removeDirectory($directoryPath, $contentOnly = false)
|
public static function removeDirectory($directoryPath, $contentOnly = false)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* Directory does not exist?
|
||||||
|
* Nothing to do
|
||||||
|
*/
|
||||||
if (!file_exists($directoryPath)) {
|
if (!file_exists($directoryPath)) {
|
||||||
return true;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* It's not a directory?
|
||||||
|
* Let's treat it like file
|
||||||
|
*/
|
||||||
if (!is_dir($directoryPath)) {
|
if (!is_dir($directoryPath)) {
|
||||||
return unlink($directoryPath);
|
return unlink($directoryPath);
|
||||||
}
|
}
|
||||||
@@ -741,6 +749,9 @@ class Miscellaneous
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Directory should be removed too?
|
||||||
|
*/
|
||||||
if (!$contentOnly) {
|
if (!$contentOnly) {
|
||||||
return rmdir($directoryPath);
|
return rmdir($directoryPath);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ use Meritoo\Common\Exception\Regex\InvalidColorHexValueException;
|
|||||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||||
use Meritoo\Common\Utilities\Locale;
|
use Meritoo\Common\Utilities\Locale;
|
||||||
use Meritoo\Common\Utilities\Miscellaneous;
|
use Meritoo\Common\Utilities\Miscellaneous;
|
||||||
|
use ReflectionException;
|
||||||
use stdClass;
|
use stdClass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -28,6 +29,9 @@ class MiscellaneousTest extends BaseTestCase
|
|||||||
private $stringCommaSeparated;
|
private $stringCommaSeparated;
|
||||||
private $stringDotSeparated;
|
private $stringDotSeparated;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws ReflectionException
|
||||||
|
*/
|
||||||
public function testConstructor()
|
public function testConstructor()
|
||||||
{
|
{
|
||||||
static::assertHasNoConstructor(Miscellaneous::class);
|
static::assertHasNoConstructor(Miscellaneous::class);
|
||||||
@@ -363,35 +367,33 @@ class MiscellaneousTest extends BaseTestCase
|
|||||||
self::assertEquals('Lorem ipsum dolor sit---amet, consectetur---adipiscing---elit', Miscellaneous::breakLongText($this->stringCommaSeparated, 20, '---'));
|
self::assertEquals('Lorem ipsum dolor sit---amet, consectetur---adipiscing---elit', Miscellaneous::breakLongText($this->stringCommaSeparated, 20, '---'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRemoveDirectory()
|
public function testRemoveDirectoryUsingNotExistingDirectory()
|
||||||
{
|
{
|
||||||
/*
|
self::assertNull(Miscellaneous::removeDirectory('/abc/def/ghi'));
|
||||||
* Removing not existing directory
|
}
|
||||||
*/
|
|
||||||
self::assertTrue(Miscellaneous::removeDirectory('/abc/def/ghi'));
|
|
||||||
|
|
||||||
/*
|
public function testRemoveDirectoryUsingNoDirectory()
|
||||||
* Removing not directory
|
{
|
||||||
*/
|
|
||||||
$directoryPath = sys_get_temp_dir() . '/ipsum.txt';
|
$directoryPath = sys_get_temp_dir() . '/ipsum.txt';
|
||||||
touch($directoryPath);
|
touch($directoryPath);
|
||||||
self::assertTrue(Miscellaneous::removeDirectory($directoryPath));
|
self::assertTrue(Miscellaneous::removeDirectory($directoryPath));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
public function testRemoveDirectoryUsingSimpleDirectory()
|
||||||
* Removing simple directory
|
{
|
||||||
*/
|
|
||||||
$directoryPath = sys_get_temp_dir() . '/lorem/ipsum';
|
$directoryPath = sys_get_temp_dir() . '/lorem/ipsum';
|
||||||
mkdir($directoryPath, 0777, true);
|
mkdir($directoryPath, 0777, true);
|
||||||
self::assertTrue(Miscellaneous::removeDirectory($directoryPath));
|
self::assertTrue(Miscellaneous::removeDirectory($directoryPath));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
public function testRemoveDirectoryUsingComplexDirectory()
|
||||||
* Removing more complex directory
|
{
|
||||||
*/
|
|
||||||
$directory1Path = sys_get_temp_dir() . '/lorem/ipsum';
|
$directory1Path = sys_get_temp_dir() . '/lorem/ipsum';
|
||||||
$directory2Path = sys_get_temp_dir() . '/lorem/dolor/sit';
|
$directory2Path = sys_get_temp_dir() . '/lorem/dolor/sit';
|
||||||
|
|
||||||
mkdir($directory1Path, 0777, true);
|
mkdir($directory1Path, 0777, true);
|
||||||
mkdir($directory2Path, 0777, true);
|
mkdir($directory2Path, 0777, true);
|
||||||
|
|
||||||
self::assertTrue(Miscellaneous::removeDirectory(sys_get_temp_dir() . '/lorem', false));
|
self::assertTrue(Miscellaneous::removeDirectory(sys_get_temp_dir() . '/lorem', false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -661,6 +663,10 @@ class MiscellaneousTest extends BaseTestCase
|
|||||||
self::assertEquals(255, Miscellaneous::getValidColorComponent(255, false));
|
self::assertEquals(255, Miscellaneous::getValidColorComponent(255, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws IncorrectColorHexLengthException
|
||||||
|
* @throws InvalidColorHexValueException
|
||||||
|
*/
|
||||||
public function testGetInvertedColorWithIncorrectLength()
|
public function testGetInvertedColorWithIncorrectLength()
|
||||||
{
|
{
|
||||||
$this->setExpectedException(IncorrectColorHexLengthException::class);
|
$this->setExpectedException(IncorrectColorHexLengthException::class);
|
||||||
@@ -675,6 +681,10 @@ class MiscellaneousTest extends BaseTestCase
|
|||||||
Miscellaneous::getInvertedColor('1234567');
|
Miscellaneous::getInvertedColor('1234567');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws IncorrectColorHexLengthException
|
||||||
|
* @throws InvalidColorHexValueException
|
||||||
|
*/
|
||||||
public function testGetInvertedColorWithInvalidValue()
|
public function testGetInvertedColorWithInvalidValue()
|
||||||
{
|
{
|
||||||
$this->setExpectedException(InvalidColorHexValueException::class);
|
$this->setExpectedException(InvalidColorHexValueException::class);
|
||||||
@@ -686,6 +696,10 @@ class MiscellaneousTest extends BaseTestCase
|
|||||||
Miscellaneous::getInvertedColor('00ppqq');
|
Miscellaneous::getInvertedColor('00ppqq');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws IncorrectColorHexLengthException
|
||||||
|
* @throws InvalidColorHexValueException
|
||||||
|
*/
|
||||||
public function testGetInvertedColor()
|
public function testGetInvertedColor()
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user