ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
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)
 
- Public Member Functions inherited from ILIAS\Refinery\Transformation
 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.

Referenced by ILIAS\Refinery\String\EstimatedReadingTime\transform().

147  : void
148  {
149  $currentErrors = libxml_get_errors();
150  libxml_clear_errors();
151 
152  $this->xmlErrors = $currentErrors;
153  }
+ Here is the caller graph for this function:

◆ beginXmlLogging()

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

Definition at line 141 of file EstimatedReadingTime.php.

Referenced by ILIAS\Refinery\String\EstimatedReadingTime\transform().

141  : void
142  {
143  $this->xmlErrorState = libxml_use_internal_errors(true);
144  libxml_clear_errors();
145  }
+ Here is the caller graph for this function:

◆ 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.

References $i.

Referenced by ILIAS\Refinery\String\EstimatedReadingTime\transform().

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  }
$i
Definition: metadata.php:41
+ Here is the caller graph for this function:

◆ endXmlLogging()

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

Definition at line 155 of file EstimatedReadingTime.php.

Referenced by ILIAS\Refinery\String\EstimatedReadingTime\transform().

155  : void
156  {
157  libxml_use_internal_errors($this->xmlErrorState);
158  }
+ Here is the caller graph for this function:

◆ transform()

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

Implements ILIAS\Refinery\Transformation.

Definition at line 53 of file EstimatedReadingTime.php.

References Vendor\Package\$e, $message, ILIAS\Refinery\String\EstimatedReadingTime\addErrors(), ILIAS\Refinery\String\EstimatedReadingTime\beginXmlLogging(), ILIAS\Refinery\String\EstimatedReadingTime\calculateWordsForImages(), and ILIAS\Refinery\String\EstimatedReadingTime\endXmlLogging().

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  }
+ Here is the call graph for this function:

◆ 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.

References ILIAS\$error.

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:55

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: