Skip to content
Merged
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
17 changes: 9 additions & 8 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:
operating-system: [ubuntu-20.04]
php-versions: ['7.4', '8.0', '8.1']
dependencies: ['no', 'low', 'beta']
include:
exclude:
- operating-system: ubuntu-20.04
php-versions: '8.0'
continue-on-error: true
php-versions: '8.1'
dependencies: 'low'

name: PHP ${{ matrix.php-versions }} - ${{ matrix.dependencies }}

Expand Down Expand Up @@ -58,6 +58,10 @@ jobs:
path: ~/.composer/cache/files
key: dependencies-composer-${{ hashFiles('composer.json') }}

- name: Fix beta
if: ${{ matrix.dependencies == 'beta' }}
run: perl -pi -e 's/^}$/,"minimum-stability":"beta"}/' composer.json

- name: Setup PHP Action
uses: shivammathur/[email protected]
with:
Expand Down Expand Up @@ -91,8 +95,5 @@ jobs:
- name: Validate files
run: composer validate-files

- name: Check Style
run: composer check-code-style

# - name: Run tests
# run: composer run-tests
- name: Run tests
run: composer run-tests
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ composer.phar
composer.lock
.DS_Store
.php-cs-fixer.cache
.phpunit.result.cache
.phpunit.result.cache
11 changes: 2 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,10 @@

"require-dev": {
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpmd/phpmd": "^2.9",
"phpunit/phpunit": "^9.3",
"sebastian/phpcpd": ">=4.1",
"friendsofphp/php-cs-fixer": ">=2.17",
"squizlabs/php_codesniffer": "^3.5"
"phpunit/phpunit": "^9.3"
},

"scripts": {
"check-code-style": [
"vendor/bin/phpcs --standard=PSR2 ./src/"
],
"run-tests": [
"vendor/bin/phpunit -c phpunit.xml",
"vendor/bin/phpunit --coverage-clover=coverage.xml"
Expand All @@ -59,4 +52,4 @@
]
}
}
}
}
26 changes: 13 additions & 13 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="phpunit.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory>./src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="phpunit.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory>./src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
4 changes: 1 addition & 3 deletions src/AncestorsRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ class AncestorsRelation extends BaseRelation
*/
public function addConstraints()
{
if (! static::$constraints) {
return;
}
if ( ! static::$constraints) return;

$this->query->whereAncestorOf($this->parent)
->applyNestedSetScope();
Expand Down
14 changes: 5 additions & 9 deletions src/BaseRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ abstract class BaseRelation extends Relation
*/
public function __construct(QueryBuilder $builder, Model $model)
{
if (! NestedSet::isNode($model)) {
if ( ! NestedSet::isNode($model)) {
throw new InvalidArgumentException('Model must be node.');
}

Expand Down Expand Up @@ -76,10 +76,8 @@ abstract protected function relationExistenceCondition($hash, $table, $lft, $rgt
*
* @return mixed
*/
public function getRelationExistenceQuery(
EloquentBuilder $query,
EloquentBuilder $parent,
$columns = [ '*' ]
public function getRelationExistenceQuery(EloquentBuilder $query, EloquentBuilder $parent,
$columns = [ '*' ]
) {
$query = $this->getParent()->replicate()->newScopedQuery()->select($columns);

Expand All @@ -95,8 +93,7 @@ public function getRelationExistenceQuery(
$grammar->wrapTable($hash),
$grammar->wrapTable($table),
$grammar->wrap($this->parent->getLftName()),
$grammar->wrap($this->parent->getRgtName())
);
$grammar->wrap($this->parent->getRgtName()));

return $query->whereRaw($condition);
}
Expand All @@ -122,8 +119,7 @@ public function initRelation(array $models, $relation)
* @return mixed
*/
public function getRelationQuery(
EloquentBuilder $query,
EloquentBuilder $parent,
EloquentBuilder $query, EloquentBuilder $parent,
$columns = [ '*' ]
) {
return $this->getRelationExistenceQuery($query, $parent, $columns);
Expand Down
17 changes: 7 additions & 10 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ class Collection extends BaseCollection
*/
public function linkNodes()
{
if ($this->isEmpty()) {
return $this;
}
if ($this->isEmpty()) return $this;

$groupedNodes = $this->groupBy($this->first()->getParentIdName());

/** @var NodeTrait|Model $node */
foreach ($this->items as $node) {
if (! $node->getParentId()) {
if ( ! $node->getParentId()) {
$node->setRelation('parent', null);
}

Expand Down Expand Up @@ -55,7 +53,7 @@ public function linkNodes()
public function toTree($root = false)
{
if ($this->isEmpty()) {
return new static();
return new static;
}

$this->linkNodes();
Expand Down Expand Up @@ -114,11 +112,9 @@ protected function getRootNodeId($root = false)
*/
public function toFlatTree($root = false)
{
$result = new static();
$result = new static;

if ($this->isEmpty()) {
return $result;
}
if ($this->isEmpty()) return $result;

$groupedNodes = $this->groupBy($this->first()->getParentIdName());

Expand All @@ -143,4 +139,5 @@ protected function flattenTree(self $groupedNodes, $parentId)

return $this;
}
}

}
7 changes: 3 additions & 4 deletions src/DescendantsRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@

class DescendantsRelation extends BaseRelation
{

/**
* Set the base constraints on the relation query.
*
* @return void
*/
public function addConstraints()
{
if (! static::$constraints) {
return;
}
if ( ! static::$constraints) return;

$this->query->whereDescendantOf($this->parent)
->applyNestedSetScope();
Expand Down Expand Up @@ -54,4 +53,4 @@ protected function relationExistenceCondition($hash, $table, $lft, $rgt)
{
return "{$hash}.{$lft} between {$table}.{$lft} + 1 and {$table}.{$rgt}";
}
}
}
13 changes: 7 additions & 6 deletions src/NestedSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@ class NestedSet
/**
* The name of default lft column.
*/
public const LFT = '_lft';
const LFT = '_lft';

/**
* The name of default rgt column.
*/
public const RGT = '_rgt';
const RGT = '_rgt';

/**
* The name of default parent id column.
*/
public const PARENT_ID = 'parent_id';
const PARENT_ID = 'parent_id';

/**
* Insert direction.
*/
public const BEFORE = 1;
const BEFORE = 1;

/**
* Insert direction.
*/
public const AFTER = 2;
const AFTER = 2;

/**
* Add default nested set columns to the table. Also create an index.
Expand Down Expand Up @@ -79,4 +79,5 @@ public static function isNode($node)
{
return $node instanceof Node;
}
}

}
2 changes: 1 addition & 1 deletion src/NestedSetServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ public function register()
NestedSet::dropColumns($this);
});
}
}
}
Loading