Skip to content

Commit d8c1e3b

Browse files
authored
add more php-doc for phpstan (#18)
1 parent e6e9986 commit d8c1e3b

File tree

6 files changed

+54
-13
lines changed

6 files changed

+54
-13
lines changed

src/Contracts/NestedSetCollection.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,32 @@ public function toTree($root = false): NestedSetCollection;
4646
* @return NestedSetCollection<Tmodel>
4747
*/
4848
public function toFlatTree($root = false): NestedSetCollection;
49+
50+
/**
51+
* Count the number of items in the collection.
52+
*
53+
* @return int
54+
*/
55+
public function count(): int;
56+
57+
/**
58+
* Get the values of a given key.
59+
*
60+
* @param string|int|array<array-key, string>|null $value
61+
* @param string|null $key
62+
*
63+
* @return \Illuminate\Support\Collection<array-key, mixed>
64+
*/
65+
public function pluck($value, $key = null);
66+
67+
/**
68+
* Run a map over each of the items.
69+
*
70+
* @template TMapValue
71+
*
72+
* @param callable(NodeModel, int): TMapValue $callback
73+
*
74+
* @return \Illuminate\Support\Collection<int, TMapValue>
75+
*/
76+
public function map(callable $callback);
4977
}

tests/NodeTest.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
<?php
22

3+
namespace tests;
4+
35
use Illuminate\Database\Capsule\Manager as Capsule;
6+
use Illuminate\Database\Schema\Blueprint;
47
use Kalnoy\Nestedset\NestedSet;
8+
use PHPUnit\Framework\TestCase;
9+
use tests\models\Category;
510

6-
class NodeTest extends PHPUnit\Framework\TestCase
11+
class NodeTest extends TestCase
712
{
813
public static function setUpBeforeClass(): void
914
{
@@ -13,7 +18,7 @@ public static function setUpBeforeClass(): void
1318

1419
Capsule::disableQueryLog();
1520

16-
$schema->create('categories', function (Illuminate\Database\Schema\Blueprint $table) {
21+
$schema->create('categories', function (Blueprint $table) {
1722
$table->increments('id');
1823
$table->string('name');
1924
$table->softDeletes();
@@ -225,7 +230,7 @@ public function testCategoryMovesUp()
225230

226231
public function testFailsToInsertIntoChild()
227232
{
228-
$this->expectException(Exception::class);
233+
$this->expectException(\Exception::class);
229234

230235
$node = $this->findCategory('notebooks');
231236
$target = $node->children()->first();
@@ -235,7 +240,7 @@ public function testFailsToInsertIntoChild()
235240

236241
public function testFailsToAppendIntoItself()
237242
{
238-
$this->expectException(Exception::class);
243+
$this->expectException(\Exception::class);
239244

240245
$node = $this->findCategory('notebooks');
241246

@@ -244,7 +249,7 @@ public function testFailsToAppendIntoItself()
244249

245250
public function testFailsToPrependIntoItself()
246251
{
247-
$this->expectException(Exception::class);
252+
$this->expectException(\Exception::class);
248253

249254
$node = $this->findCategory('notebooks');
250255

@@ -339,7 +344,7 @@ public function testParentIdAttributeAccessorAppendsNode()
339344

340345
public function testFailsToSaveNodeUntilNotInserted()
341346
{
342-
$this->expectException(Exception::class);
347+
$this->expectException(\Exception::class);
343348

344349
$node = new Category();
345350
$node->save();
@@ -405,7 +410,7 @@ public function testSoftDeletedNodeisDeletedWhenParentIsDeleted()
405410

406411
public function testFailsToSaveNodeUntilParentIsSaved()
407412
{
408-
$this->expectException(Exception::class);
413+
$this->expectException(\Exception::class);
409414

410415
$node = new Category(['title' => 'Node']);
411416
$parent = new Category(['title' => 'Parent']);

tests/ScopedNodeTest.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<?php
22

3+
namespace tests;
4+
35
use Illuminate\Database\Capsule\Manager as Capsule;
46
use Kalnoy\Nestedset\NestedSet;
7+
use PHPUnit\Framework\TestCase;
8+
use tests\models\MenuItem;
59

6-
include __DIR__ . '/models/MenuItem.php';
7-
8-
class ScopedNodeTest extends PHPUnit\Framework\TestCase
10+
class ScopedNodeTest extends TestCase
911
{
1012
public static function setUpBeforeClass(): void
1113
{
@@ -15,7 +17,7 @@ public static function setUpBeforeClass(): void
1517

1618
Capsule::disableQueryLog();
1719

18-
$schema->create('menu_items', function (Illuminate\Database\Schema\Blueprint $table) {
20+
$schema->create('menu_items', function (\Illuminate\Database\Schema\Blueprint $table) {
1921
$table->increments('id');
2022
$table->unsignedInteger('menu_id');
2123
$table->string('title')->nullable();
@@ -204,7 +206,7 @@ protected function assertOtherScopeNotAffected()
204206

205207
public function testAppendingToAnotherScopeFails()
206208
{
207-
$this->expectException(LogicException::class);
209+
$this->expectException(\LogicException::class);
208210

209211
$a = MenuItem::find(1);
210212
$b = MenuItem::find(3);
@@ -214,7 +216,7 @@ public function testAppendingToAnotherScopeFails()
214216

215217
public function testInsertingBeforeAnotherScopeFails()
216218
{
217-
$this->expectException(LogicException::class);
219+
$this->expectException(\LogicException::class);
218220

219221
$a = MenuItem::find(1);
220222
$b = MenuItem::find(3);

tests/models/Category.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace tests\models;
4+
35
use Illuminate\Database\Eloquent\Model;
46
use Illuminate\Database\Eloquent\SoftDeletes;
57
use Kalnoy\Nestedset\Contracts\Node;

tests/models/DuplicateCategory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace tests\models;
4+
35
use Illuminate\Database\Eloquent\Model;
46
use Kalnoy\Nestedset\Contracts\Node;
57
use Kalnoy\Nestedset\NodeTrait;

tests/models/MenuItem.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace tests\models;
4+
35
use Illuminate\Database\Eloquent\Model;
46
use Kalnoy\Nestedset\Contracts\Node;
57
use Kalnoy\Nestedset\NodeTrait;

0 commit comments

Comments
 (0)