Skip to content

Commit

Permalink
Some micro optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
theseer committed Feb 6, 2018
1 parent 30ca120 commit d0766e8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/formdata/FormData.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ public function getValue(string $key) {
private function initValuesFromArray(array $values, bool $recursion = false): array {
$result = [];
foreach($values as $key => $value) {
if (is_string($value)) {
if (\is_string($value)) {
$result[$key] = $value;
continue;
}
if ($recursion === false && is_array($value)) {
if ($recursion === false && \is_array($value)) {
$result[$key] = $this->initValuesFromArray($value, true);
continue;
}
throw new FormDataException(
sprintf('Data type "%s" in key "%s" not supported', gettype($value), $key)
sprintf('Data type "%s" in key "%s" not supported', \gettype($value), $key)
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/snippet/SnippetList.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function rewind() {
}

public function count(): int {
return count($this->snippets);
return \count($this->snippets);
}

}
6 changes: 3 additions & 3 deletions src/viewmodel/SnapshotDOMNodelist.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(DOMNodeList $list) {
}

public function count() {
return count($this->items);
return \count($this->items);
}

public function hasNode(DOMNode $node) {
Expand Down Expand Up @@ -66,7 +66,7 @@ public function key(): int {
}

public function valid(): bool {
$count = count($this->items);
$count = \count($this->items);
return $count > 0 && $count > $this->pos;
}

Expand All @@ -81,7 +81,7 @@ private function extractItemsFromNodeList(DOMNodeList $list) {
}

public function hasNext(): bool {
$count = count($this->items);
$count = \count($this->items);
return $count > 0 && $this->pos < $count;
}

Expand Down
17 changes: 8 additions & 9 deletions src/viewmodel/ViewModelRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private function dropFromStack() {
*/
private function applyCurrent(DOMElement $context): DOMNode {
$model = $this->current();
switch (gettype($model)) {
switch (\gettype($model)) {
case 'boolean': {
return $this->processBoolean($context, $model);
}
Expand All @@ -125,7 +125,7 @@ private function applyCurrent(DOMElement $context): DOMNode {

default: {
throw new ViewModelRendererException(
sprintf('Unsupported type %s', gettype($model))
sprintf('Unsupported type %s', \gettype($model))
);
}
}
Expand Down Expand Up @@ -194,9 +194,8 @@ private function processObjectAsModel(DOMElement $context, $model): DOMElement {
* @throws ViewModelRendererException
*/
private function processArray(DOMElement $context, $model): DOMDocumentFragment {
$count = count($model);
if ($context->isSameNode($context->ownerDocument->documentElement) &&
$count > 1) {
$count = \count($model);
if ($count > 1 && $context->isSameNode($context->ownerDocument->documentElement)) {
throw new ViewModelRendererException(
'Cannot render multiple copies of root element'
);
Expand Down Expand Up @@ -288,10 +287,10 @@ function (&$value, $pos) { $value = ucfirst($value); }
return;
}

if (!is_string($value)) {
if (!\is_string($value)) {
throw new ViewModelRendererException(
sprintf('Attribute value must be string or boolean false - type %s received from $model->%s',
gettype($value),
\gettype($value),
implode('()->', $this->stackNames) . '()'
)
);
Expand All @@ -307,12 +306,12 @@ function (&$value, $pos) { $value = ucfirst($value); }
* @throws ViewModelRendererException
*/
private function ensureIsObject($model, string $property) {
if (!is_object($model)) {
if (!\is_object($model)) {
throw new ViewModelRendererException(
sprintf(
'Trying to add "%s" failed - Non object (%s) on stack: $%s',
$property,
gettype($model),
\gettype($model),
implode('()->', $this->stackNames) . '() '
)
);
Expand Down

0 comments on commit d0766e8

Please sign in to comment.