Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/PhpDoc/ExtDsStubFilesExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public function __construct(private ExtensionVersionProvider $extensionVersionPr
public function getFiles(): array
{
$version = $this->extensionVersionProvider->getExtensionVersions()['ds'] ?? null;
if ($version === 2) {
return [__DIR__ . '/../../stubs/ext-ds-v2.stub'];
}

if ($version !== null && $version !== 1) {
return [];
}
Expand Down
249 changes: 249 additions & 0 deletions stubs/ext-ds-v2.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
<?php

namespace Ds;

use ArrayAccess;
use Countable;
use IteratorAggregate;
use JsonSerializable;

/**
* @template TValue
* @implements IteratorAggregate<int, TValue>
* @implements ArrayAccess<int, TValue>
*/
final class Seq implements Countable, IteratorAggregate, JsonSerializable, ArrayAccess
{
/**
* @template TValue2
* @param iterable<TValue2> $values
* @return Seq<TValue|TValue2>
*/
public function merge($values): Seq
{
}

/**
* @template TCarry
* @param callable(TCarry, TValue): TCarry $callback
* @param TCarry $initial
* @return TCarry
*/
public function reduce(callable $callback, $initial = null)
{
}

/**
* @return list<TValue>
*/
public function toArray(): array
{
}

/**
* @return list<TValue>
*/
public function jsonSerialize(): array
{
}

/**
* @return list<TValue>
*/
public function __serialize(): array
{
}
}

/**
* @template TKey
* @template TValue
* @implements IteratorAggregate<TKey, TValue>
* @implements ArrayAccess<TKey, TValue>
*/
final class Map implements Countable, IteratorAggregate, JsonSerializable, ArrayAccess
{
/**
* @template TValue2
* @param Map<TKey, TValue2> $map
* @return Map<TKey, TValue>
*/
public function diff(Map $map): Map
{
}

/**
* @template TDefault
* @param TKey $key
* @param TDefault $default
* @return TValue|TDefault
*/
public function get($key, $default = null)
{
}

/**
* @template TKey2
* @template TValue2
* @param Map<TKey2, TValue2> $map
* @return Map<TKey&TKey2, TValue>
*/
public function intersect(Map $map): Map
{
}

/**
* @template TKey2
* @template TValue2
* @param iterable<TKey2, TValue2> $values
* @return Map<TKey|TKey2, TValue|TValue2>
*/
public function merge($values): Map
{
}

/**
* @template TCarry
* @param callable(TCarry, TKey, TValue): TCarry $callback
* @param TCarry $initial
* @return TCarry
*/
public function reduce(callable $callback, $initial = null)
{
}

/**
* @template TDefault
* @param TKey $key
* @param TDefault $default
* @return TValue|TDefault
*/
public function remove($key, $default = null)
{
}

/**
* @template TKey2
* @template TValue2
* @param Map<TKey2, TValue2> $map
* @return Map<TKey|TKey2, TValue|TValue2>
*/
public function union(Map $map): Map
{
}

/**
* @template TKey2
* @template TValue2
* @param Map<TKey2, TValue2> $map
* @return Map<TKey|TKey2, TValue|TValue2>
*/
public function xor(Map $map): Map
{
}
}

/**
* @template TValue
* @implements IteratorAggregate<int, TValue>
* @implements ArrayAccess<int, TValue>
*/
final class Set implements Countable, IteratorAggregate, JsonSerializable, ArrayAccess
{
/**
* @template TValue2
* @param Set<TValue2> $set
* @return Set<TValue>
*/
public function diff(Set $set): Set
{
}

/**
* @template TValue2
* @param Set<TValue2> $set
* @return Set<TValue&TValue2>
*/
public function intersect(Set $set): Set
{
}

/**
* @template TValue2
* @param iterable<TValue2> $values
* @return Set<TValue|TValue2>
*/
public function merge($values): Set
{
}

/**
* @template TCarry
* @param callable(TCarry, TValue): TCarry $callback
* @param TCarry $initial
* @return TCarry
*/
public function reduce(callable $callback, $initial = null)
{
}

/**
* @return list<TValue>
*/
public function toArray(): array
{
}

/**
* @return list<TValue>
*/
public function jsonSerialize(): array
{
}

/**
* @template TValue2
* @param Set<TValue2> $set
* @return Set<TValue|TValue2>
*/
public function union(Set $set): Set
{
}

/**
* @template TValue2
* @param Set<TValue2> $set
* @return Set<TValue|TValue2>
*/
public function xor(Set $set): Set
{
}
}

/**
* @template TValue
* @implements IteratorAggregate<int, TValue>
*/
final class Heap implements Countable, IteratorAggregate, JsonSerializable
{
/**
* @return list<TValue>
*/
public function toArray(): array
{
}

/**
* @return list<TValue>
*/
public function jsonSerialize(): array
{
}

/**
* @return list<TValue>
*/
public function __serialize(): array
{
}
}
41 changes: 41 additions & 0 deletions tests/PHPStan/Analyser/ExtDsV2Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php declare(strict_types = 1);

namespace PHPStan\Analyser;

use PHPStan\Testing\TypeInferenceTestCase;
use PHPUnit\Framework\Attributes\DataProvider;

class ExtDsV2Test extends TypeInferenceTestCase
{

public static function dataAsserts(): iterable
{
yield from self::gatherAssertTypes(__DIR__ . '/data/ext-ds-v2.php');
}

/**
* @param mixed ...$args
*/
#[DataProvider('dataAsserts')]
public function testAsserts(
string $assertType,
string $file,
...$args,
): void
{
$this->assertFileAsserts($assertType, $file, ...$args);
}

public static function getAdditionalConfigFiles(): array
{
return [
__DIR__ . '/../../../conf/bleedingEdge.neon',
];
}

public static function getComposerAutoloaderProjectPaths(): array
{
return [__DIR__ . '/data/ext-ds-v2-platform'];
}

}
5 changes: 5 additions & 0 deletions tests/PHPStan/Analyser/data/ext-ds-v2-platform/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require": {
"ext-ds": "^2"
}
}
Loading
Loading