Skip to content

Commit

Permalink
Merge pull request #59 from MaxGoryunov/feature/51
Browse files Browse the repository at this point in the history
Feature/51
  • Loading branch information
MaxGoryunov committed Jul 30, 2021
2 parents 0927623 + 8b869eb commit 54fa0bb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
12 changes: 6 additions & 6 deletions fakes/Let.php
Expand Up @@ -10,7 +10,7 @@
*
* @todo #44:25min Classes Let and The contain some repeated cdde which could
* be extracted into a separate class.
* @template x subject type
* @template X subject type
* @template Y result type
* @implements \MaxGoryunov\SavingIterator\Src\Scalar<Y>
*/
Expand All @@ -20,21 +20,21 @@ class Let implements Scalar
/**
* Ctor.
*
* @param mixed $subject
* @param Closure $context
* @param X $subject
* @param Closure(X): Y $context
*/
public function __construct(
/**
* Element to be put into the context.
*
* @var mixed
* @var X
*/
private mixed $subject,

/**
* Context for the element.
*
* @var Closure
* @var Closure(X): Y
*/
private Closure $context
) {
Expand All @@ -43,7 +43,7 @@ public function __construct(
/**
* Returns result of applying context to element.
*
* @return mixed
* @return Y
*/
public function value(): mixed
{
Expand Down
13 changes: 5 additions & 8 deletions fakes/The.php
Expand Up @@ -8,9 +8,6 @@
/**
* Class for applying contexts to elements without changing them.
*
* @todo #44:20min Classes Let and The do not have proper type hints in
* constructor and methods. Workarounds with `@var` tags must be removed
* after that.
* @template T subject type
* @implements \MaxGoryunov\SavingIterator\Src\Scalar<T>
*/
Expand All @@ -20,21 +17,21 @@ class The implements Scalar
/**
* Ctor.
*
* @param mixed $subject
* @param Closure $context
* @param T $subject
* @param Closure(T): mixed $context
*/
public function __construct(
/**
* Element to be put into the context.
*
* @var mixed
* @var T
*/
private mixed $subject,

/**
* Context for the element.
*
* @var Closure
* @var Closure(T): mixed
*/
private Closure $context
) {
Expand All @@ -43,7 +40,7 @@ public function __construct(
/**
* Applies context to subject and returns subject.
*
* @return mixed
* @return T
*/
public function value(): mixed
{
Expand Down
9 changes: 9 additions & 0 deletions tests/src/SavingIteratorTest.php
Expand Up @@ -16,6 +16,13 @@

/**
* @coversDefaultClass MaxGoryunov\SavingIterator\Src\SavingIterator
*
* @todo #51:30min It seems that The and Let new typehints have a negative
* effect on PHPStan in a way that when type coming to The or Let is not
* typehinted as plain `mixed` or `Closure` PHPStan starts complaining about
* types for `TransparentIterator` for example. It should probably be solved
* by prefixing tags for PHPStan with `phpstan`. It also causes IDE to
* complain about incorrect types(X or T or Y instead of some expected type).
*/
class SavingIteratorTest extends TestCase
{
Expand Down Expand Up @@ -79,6 +86,7 @@ public function testDoesNotCallOriginIfValuesAreInCache(): void
new LimitIterator(
new InfiniteIterator(
new SavingIterator(
/** @phpstan-ignore-next-line */
new TransparentIterator($called)
)
),
Expand Down Expand Up @@ -305,6 +313,7 @@ public function testFillsCacheValueOnlyIfItIsNotStoredYet(): void
new LimitIterator(
new InfiniteIterator(
new SavingIterator(
/** @phpstan-ignore-next-line */
new TransparentIterator($called)
)
),
Expand Down

2 comments on commit 54fa0bb

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 54fa0bb Jul 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 44-d8e690f3 disappeared from fakes/The.php, that's why I closed #51. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 54fa0bb Jul 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 51-659aec35 discovered in tests/src/SavingIteratorTest.php and submitted as #64. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.