mirror of
https://github.com/wallabag/wallabag.git
synced 2025-09-30 19:22:12 +00:00
Extract DEFAULT_WORDS_PER_MINUTE in Utils
This is done In order to avoid having magic numbers in the code
This commit is contained in:
parent
d24b703315
commit
797d48905c
3 changed files with 8 additions and 4 deletions
|
@ -14,6 +14,7 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||||
use Wallabag\AnnotationBundle\Entity\Annotation;
|
use Wallabag\AnnotationBundle\Entity\Annotation;
|
||||||
use Wallabag\CoreBundle\Helper\EntityTimestampsTrait;
|
use Wallabag\CoreBundle\Helper\EntityTimestampsTrait;
|
||||||
use Wallabag\CoreBundle\Helper\UrlHasher;
|
use Wallabag\CoreBundle\Helper\UrlHasher;
|
||||||
|
use Wallabag\CoreBundle\Tools\Utils;
|
||||||
use Wallabag\UserBundle\Entity\User;
|
use Wallabag\UserBundle\Entity\User;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -663,7 +664,7 @@ class Entry
|
||||||
*/
|
*/
|
||||||
public function getUserReadingTime()
|
public function getUserReadingTime()
|
||||||
{
|
{
|
||||||
return round($this->readingTime / $this->getUser()->getConfig()->getReadingSpeed() * 200);
|
return round($this->readingTime / $this->getUser()->getConfig()->getReadingSpeed() * Utils::DEFAULT_WORDS_PER_MINUTE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -16,6 +16,7 @@ use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||||
use Wallabag\CoreBundle\Repository\EntryRepository;
|
use Wallabag\CoreBundle\Repository\EntryRepository;
|
||||||
|
use Wallabag\CoreBundle\Tools\Utils;
|
||||||
use Wallabag\UserBundle\Entity\User;
|
use Wallabag\UserBundle\Entity\User;
|
||||||
|
|
||||||
class EntryFilterType extends AbstractType
|
class EntryFilterType extends AbstractType
|
||||||
|
@ -57,8 +58,8 @@ class EntryFilterType extends AbstractType
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$min = (int) ($lower * $user->getConfig()->getReadingSpeed() / 200);
|
$min = (int) ($lower * $user->getConfig()->getReadingSpeed() / Utils::DEFAULT_WORDS_PER_MINUTE);
|
||||||
$max = (int) ($upper * $user->getConfig()->getReadingSpeed() / 200);
|
$max = (int) ($upper * $user->getConfig()->getReadingSpeed() / Utils::DEFAULT_WORDS_PER_MINUTE);
|
||||||
|
|
||||||
if (null === $lower && null !== $upper) {
|
if (null === $lower && null !== $upper) {
|
||||||
// only lower value is defined: query all entries with reading LOWER THAN this value
|
// only lower value is defined: query all entries with reading LOWER THAN this value
|
||||||
|
|
|
@ -4,6 +4,8 @@ namespace Wallabag\CoreBundle\Tools;
|
||||||
|
|
||||||
class Utils
|
class Utils
|
||||||
{
|
{
|
||||||
|
public const DEFAULT_WORDS_PER_MINUTE = 200;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a token used for Feeds.
|
* Generate a token used for Feeds.
|
||||||
*
|
*
|
||||||
|
@ -28,6 +30,6 @@ class Utils
|
||||||
*/
|
*/
|
||||||
public static function getReadingTime($text)
|
public static function getReadingTime($text)
|
||||||
{
|
{
|
||||||
return floor(\count(preg_split('~([^\p{L}\p{N}\']+|(\p{Han}|\p{Hiragana}|\p{Katakana}|\p{Hangul}){1,2})~u', strip_tags($text))) / 200);
|
return floor(\count(preg_split('~([^\p{L}\p{N}\']+|(\p{Han}|\p{Hiragana}|\p{Katakana}|\p{Hangul}){1,2})~u', strip_tags($text))) / self::DEFAULT_WORDS_PER_MINUTE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue