ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\Refinery\String\EstimatedReadingTime Class Reference
+ Inheritance diagram for ILIAS\Refinery\String\EstimatedReadingTime:
+ Collaboration diagram for ILIAS\Refinery\String\EstimatedReadingTime:

Public Member Functions

 __construct (bool $withImages)
 
 transform ($from)
 @inheritDoc More...
 
- Public Member Functions inherited from ILIAS\Refinery\Transformation
 transform ($from)
 Perform the transformation. More...
 
 applyTo (Result $result)
 Perform the transformation and reify possible failures. More...
 
 __invoke ($from)
 Transformations should be callable. More...
 

Private Member Functions

 calculateWordsForImages (int $numberOfImages)
 
 beginXmlLogging ()
 
 addErrors ()
 
 endXmlLogging ()
 
 xmlErrorsOccurred ()
 
 xmlErrorsToString ()
 

Private Attributes

int $wordsPerMinute = 275
 
bool $withImages
 
bool $xmlErrorState = false
 
array $xmlErrors = []
 

Detailed Description

Definition at line 34 of file EstimatedReadingTime.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Refinery\String\EstimatedReadingTime::__construct ( bool  $withImages)

Member Function Documentation

◆ addErrors()

ILIAS\Refinery\String\EstimatedReadingTime::addErrors ( )
private

Definition at line 147 of file EstimatedReadingTime.php.

147 : void
148 {
149 $currentErrors = libxml_get_errors();
150 libxml_clear_errors();
151
152 $this->xmlErrors = $currentErrors;
153 }

◆ beginXmlLogging()

ILIAS\Refinery\String\EstimatedReadingTime::beginXmlLogging ( )
private

Definition at line 141 of file EstimatedReadingTime.php.

141 : void
142 {
143 $this->xmlErrorState = libxml_use_internal_errors(true);
144 libxml_clear_errors();
145 }

◆ calculateWordsForImages()

ILIAS\Refinery\String\EstimatedReadingTime::calculateWordsForImages ( int  $numberOfImages)
private
See also
https://blog.medium.com/read-time-and-you-bc2048ab620c
Parameters
int$numberOfImages
Returns
float The calculated reading time for the passed number of images translated to words

Definition at line 126 of file EstimatedReadingTime.php.

126 : float
127 {
128 $time = 0.0;
129
130 for ($i = 1; $i <= $numberOfImages; $i++) {
131 if ($i >= 10) {
132 $time += 3 * ($this->wordsPerMinute / 60);
133 } else {
134 $time += (12 - ($i - 1)) * ($this->wordsPerMinute / 60);
135 }
136 }
137
138 return $time;
139 }

◆ endXmlLogging()

ILIAS\Refinery\String\EstimatedReadingTime::endXmlLogging ( )
private

Definition at line 155 of file EstimatedReadingTime.php.

155 : void
156 {
157 libxml_use_internal_errors($this->xmlErrorState);
158 }

◆ transform()

ILIAS\Refinery\String\EstimatedReadingTime::transform (   $from)

@inheritDoc

Implements ILIAS\Refinery\Transformation.

Definition at line 53 of file EstimatedReadingTime.php.

53 : int
54 {
55 if (!is_string($from)) {
56 throw new InvalidArgumentException(__METHOD__ . ' the argument is not a string.');
57 }
58
59 return $this->calculate($from);
60 }

◆ xmlErrorsOccurred()

ILIAS\Refinery\String\EstimatedReadingTime::xmlErrorsOccurred ( )
private

Definition at line 160 of file EstimatedReadingTime.php.

160 : bool
161 {
162 return $this->xmlErrors !== [];
163 }

◆ xmlErrorsToString()

ILIAS\Refinery\String\EstimatedReadingTime::xmlErrorsToString ( )
private

Definition at line 165 of file EstimatedReadingTime.php.

165 : string
166 {
167 $text = '';
168 foreach ($this->xmlErrors as $error) {
169 $text .= implode(',', [
170 'level=' . $error->level,
171 'code=' . $error->code,
172 'line=' . $error->line,
173 'col=' . $error->column,
174 'msg=' . trim($error->message)
175 ]) . "\n";
176 }
177
178 return $text;
179 }
ilErrorHandling $error
Definition: class.ilias.php:69

References ILIAS\$error.

Field Documentation

◆ $withImages

bool ILIAS\Refinery\String\EstimatedReadingTime::$withImages
private

◆ $wordsPerMinute

int ILIAS\Refinery\String\EstimatedReadingTime::$wordsPerMinute = 275
private

Definition at line 39 of file EstimatedReadingTime.php.

◆ $xmlErrors

array ILIAS\Refinery\String\EstimatedReadingTime::$xmlErrors = []
private

Definition at line 43 of file EstimatedReadingTime.php.

◆ $xmlErrorState

bool ILIAS\Refinery\String\EstimatedReadingTime::$xmlErrorState = false
private

Definition at line 41 of file EstimatedReadingTime.php.


The documentation for this class was generated from the following file: