From 5578b051a75c77d456ab9f99cec4bc2a02de2759 Mon Sep 17 00:00:00 2001 From: Meritoo Date: Tue, 3 Apr 2018 08:26:51 +0200 Subject: [PATCH] Update PHPDoc and comments --- src/Utilities/Date.php | 8 +++++++ src/Utilities/QueryBuilderUtility.php | 6 +++-- src/Utilities/Regex.php | 32 +++++++++++++++++++++++++++ src/Utilities/Repository.php | 11 +++++++-- 4 files changed, 53 insertions(+), 4 deletions(-) diff --git a/src/Utilities/Date.php b/src/Utilities/Date.php index 827e973..c19c530 100644 --- a/src/Utilities/Date.php +++ b/src/Utilities/Date.php @@ -10,6 +10,7 @@ namespace Meritoo\Common\Utilities; use DateInterval; use DateTime; +use Exception; use Meritoo\Common\Exception\Date\UnknownDatePartTypeException; use Meritoo\Common\Type\DatePartType; use Meritoo\Common\Type\DatePeriod; @@ -68,6 +69,8 @@ class Date * * @param int $period The period, type of period. One of DatePeriod class constants, e.g. DatePeriod::LAST_WEEK. * @return null|DatePeriod + * + * @throws Exception */ public static function getDatesForPeriod($period) { @@ -219,6 +222,7 @@ class Date * Returns current day of week * * @return int + * @throws UnknownDatePartTypeException */ public static function getCurrentDayOfWeek() { @@ -485,6 +489,8 @@ class Date * placeholder which is replaced with a number that represents each iteration. * Default: interval for days. * @return array + * + * @throws Exception */ public static function getDatesCollection(DateTime $startDate, $datesCount, $intervalTemplate = 'P%dD') { @@ -530,6 +536,8 @@ class Date * @param string $intervalTemplate (optional) Template used to build date interval. The placeholder is replaced * with next, iterated value. * @return DateTime + * + * @throws Exception */ public static function getRandomDate(DateTime $startDate = null, $start = 1, $end = 100, $intervalTemplate = 'P%sD') { diff --git a/src/Utilities/QueryBuilderUtility.php b/src/Utilities/QueryBuilderUtility.php index 294879d..037a9bd 100644 --- a/src/Utilities/QueryBuilderUtility.php +++ b/src/Utilities/QueryBuilderUtility.php @@ -10,6 +10,7 @@ namespace Meritoo\Common\Utilities; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\EntityManager; +use Doctrine\ORM\OptimisticLockException; use Doctrine\ORM\Query\Expr\Join; use Doctrine\ORM\Query\Parameter; use Doctrine\ORM\QueryBuilder; @@ -155,9 +156,10 @@ class QueryBuilderUtility * * @param EntityManager $entityManager The entity manager * @param array|ArrayCollection $entities The entities to delete - * @param bool $flushDeleted (optional) If is set to true, flushes the deleted objects. - * Otherwise - not. + * @param bool $flushDeleted (optional) If is set to true, flushes the deleted objects (default + * behaviour). Otherwise - not. * @return bool + * @throws OptimisticLockException */ public static function deleteEntities(EntityManager $entityManager, $entities, $flushDeleted = true) { diff --git a/src/Utilities/Regex.php b/src/Utilities/Regex.php index f281746..638552e 100644 --- a/src/Utilities/Regex.php +++ b/src/Utilities/Regex.php @@ -59,6 +59,10 @@ class Regex */ public static function isValidEmail($email) { + /* + * Not a string? + * Nothing to do + */ if (!is_string($email)) { return false; } @@ -141,6 +145,14 @@ class Regex */ public static function isValidUrl($url, $requireProtocol = false) { + /* + * Not a string? + * Nothing to do + */ + if (!is_string($url)) { + return false; + } + $pattern = self::getUrlPattern($requireProtocol); return (bool)preg_match($pattern, $url); @@ -154,6 +166,10 @@ class Regex */ public static function isValidPhoneNumber($phoneNumber) { + /* + * Not a string? + * Nothing to do + */ if (!is_string($phoneNumber)) { return false; } @@ -814,6 +830,10 @@ class Regex */ public static function isValidBundleName($bundleName) { + /* + * Not a string? + * Nothing to do + */ if (!is_string($bundleName)) { return false; } @@ -851,6 +871,10 @@ class Regex */ public static function isValidHtmlAttribute($htmlAttribute) { + /* + * Not a string? + * Nothing to do + */ if (!is_string($htmlAttribute)) { return false; } @@ -868,6 +892,10 @@ class Regex */ public static function areValidHtmlAttributes($htmlAttributes) { + /* + * Not a string? + * Nothing to do + */ if (!is_string($htmlAttributes)) { return false; } @@ -885,6 +913,10 @@ class Regex */ public static function isBinaryValue($value) { + /* + * Not a string? + * Nothing to do + */ if (!is_string($value)) { return false; } diff --git a/src/Utilities/Repository.php b/src/Utilities/Repository.php index 94a9737..65c07a9 100644 --- a/src/Utilities/Repository.php +++ b/src/Utilities/Repository.php @@ -10,6 +10,7 @@ namespace Meritoo\Common\Utilities; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\QueryBuilder; +use ReflectionException; /** * Useful methods for repository @@ -23,9 +24,13 @@ class Repository * Replenishes positions of given items * * @param array $items The items - * @param bool $asLast (optional) If is set to true, items are placed at the end. Otherwise - at the top. + * @param bool $asLast (optional) If is set to true, items are placed at the end (default behaviour). Otherwise + * - at top. * @param bool $force (optional) If is set to true, positions are set even there is no extreme position. - * Otherwise - if extreme position is not found (is null) replenishment is stopped / skipped. + * Otherwise - if extreme position is not found (is null) replenishment is stopped / skipped + * (default behaviour). + * + * @throws ReflectionException */ public static function replenishPositions($items, $asLast = true, $force = false) { @@ -60,6 +65,8 @@ class Repository * @param array $items The items * @param bool $max (optional) If is set to true, maximum value is returned. Otherwise - minimum. * @return int + * + * @throws ReflectionException */ public static function getExtremePosition($items, $max = true) {