Skip to content

Commit

Permalink
Merge 11f60de into 0db0403
Browse files Browse the repository at this point in the history
  • Loading branch information
vsouz4 committed Oct 16, 2020
2 parents 0db0403 + 11f60de commit 6a2b183
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [3.0.5] - 2020-10-16
### Fixed
- Collection methods use property `items` directly, without calling `toArray`

## [3.0.4] - 2020-10-16
### Fixed
- Fix `Content-type` header handling.
Expand Down
9 changes: 3 additions & 6 deletions src/Generator/SchemaCollectionGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ protected function generateToArray(Field $field): ClassMethod

protected function generateGetIterator(Field $field): ClassMethod
{
$arg = $this->builder->localMethodCall('toArray');
$arg = $this->builder->localPropertyFetch(self::INTERNAL_ARRAY_NAME);
$return = $this->builder->return($this->builder->new('ArrayIterator', [$arg]));

return $this->builder
Expand All @@ -128,7 +128,7 @@ protected function generateGetIterator(Field $field): ClassMethod
protected function generateCount(): ClassMethod
{
$return = $this->builder->return(
$this->builder->funcCall('count', [$this->builder->localMethodCall('toArray')])
$this->builder->funcCall('count', [$this->builder->localPropertyFetch(self::INTERNAL_ARRAY_NAME)])
);

return $this->builder
Expand All @@ -142,12 +142,10 @@ protected function generateCount(): ClassMethod

protected function generateFirst(Field $arrayItem): ClassMethod
{
$itemsVar = $this->builder->var('items');
$firstVar = $this->builder->var('first');
$itemsAssign = $this->builder->assign($itemsVar, $this->builder->localMethodCall('toArray'));
$resetAssign = $this->builder->assign(
$firstVar,
$this->builder->funcCall('reset', [$itemsVar])
$this->builder->funcCall('reset', [$this->builder->localPropertyFetch(self::INTERNAL_ARRAY_NAME)])
);

$ifCondition = $this->builder->equals($firstVar, $this->builder->val(false));
Expand All @@ -157,7 +155,6 @@ protected function generateFirst(Field $arrayItem): ClassMethod
return $this->builder
->method('first')
->makePublic()
->addStmt($itemsAssign)
->addStmt($resetAssign)
->addStmt($if)
->addStmt($return)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,23 @@ public function toArray(): array
*/
public function getIterator(): ArrayIterator
{
return new ArrayIterator($this->toArray());
return new ArrayIterator($this->items);
}

/**
* @return int
*/
public function count(): int
{
return \count($this->toArray());
return \count($this->items);
}

/**
* @return Item|null
*/
public function first()
{
$items = $this->toArray();
$first = \reset($items);
$first = \reset($this->items);
if ($first === false) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,23 @@ public function toArray(): array
*/
public function getIterator(): ArrayIterator
{
return new ArrayIterator($this->toArray());
return new ArrayIterator($this->items);
}

/**
* @return int
*/
public function count(): int
{
return \count($this->toArray());
return \count($this->items);
}

/**
* @return Item|null
*/
public function first(): ?Item
{
$items = $this->toArray();
$first = \reset($items);
$first = \reset($this->items);
if ($first === false) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,23 @@ public function toArray(): array
*/
public function getIterator(): ArrayIterator
{
return new ArrayIterator($this->toArray());
return new ArrayIterator($this->items);
}

/**
* @return int
*/
public function count(): int
{
return \count($this->toArray());
return \count($this->items);
}

/**
* @return Item|null
*/
public function first(): ?Item
{
$items = $this->toArray();
$first = \reset($items);
$first = \reset($this->items);
if ($first === false) {
return null;
}
Expand Down

0 comments on commit 6a2b183

Please sign in to comment.