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
98 changes: 98 additions & 0 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Tests

# Run this workflow every time a new commit pushed to your repository
on:
push:
paths-ignore:
- '**/*.md'
pull_request:
paths-ignore:
- '**/*.md'

jobs:
tests:
runs-on: ${{ matrix.operating-system }}
if: (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository)

strategy:
fail-fast: false
matrix:
operating-system: [ubuntu-20.04]
php-versions: ['7.4', '8.0', '8.1']
dependencies: ['no', 'low', 'beta']
include:
- operating-system: ubuntu-20.04
php-versions: '8.0'
continue-on-error: true

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

env:
extensions: curl json libxml dom
key: cache-v1 # can be any string, change to clear the extension cache.

steps:

# Checks out a copy of your repository on the ubuntu machine
- name: Checkout code
uses: actions/checkout@v2

- name: Setup cache environment
id: extcache
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php-versions }}
extensions: ${{ env.extensions }}
key: ${{ env.key }}

- name: Cache PHP Extensions
uses: actions/cache@v2
with:
path: ${{ steps.extcache.outputs.dir }}
key: ${{ steps.extcache.outputs.key }}
restore-keys: ${{ steps.extcache.outputs.key }}

- name: Cache Composer Dependencies
uses: actions/cache@v1
with:
path: ~/.composer/cache/files
key: dependencies-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP Action
uses: shivammathur/[email protected]
with:
php-version: ${{ matrix.php-versions }}
extensions: ${{ env.extensions }}
coverage: xdebug
tools: pecl, composer

- name: PHP Show modules
run: php -m

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install Composer dependencies
if: ${{ matrix.dependencies != 'low' }}
run: composer update --no-interaction

- name: Install Composer dependencies
if: ${{ matrix.dependencies == 'low' }}
run: composer update -vvv --prefer-lowest --prefer-stable --no-interaction

- name: Validate files
run: composer validate-files

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

# - name: Run tests
# run: composer run-tests
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
composer.phar
composer.lock
.DS_Store
.php-cs-fixer.cache
.phpunit.result.cache
15 changes: 0 additions & 15 deletions .travis.yml

This file was deleted.

21 changes: 19 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,26 @@
},

"require-dev": {
"phpunit/phpunit": "7.*"
},
"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"
},

"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"
],
"validate-files": [
"vendor/bin/parallel-lint --exclude vendor ."
]
},
"minimum-stability": "dev",
"prefer-stable": true,

Expand Down
35 changes: 13 additions & 22 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="phpunit.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./src</directory>
</whitelist>
</filter>
</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: 3 additions & 1 deletion src/AncestorsRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ 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: 9 additions & 5 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,8 +76,10 @@ 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 @@ -93,7 +95,8 @@ public function getRelationExistenceQuery(EloquentBuilder $query, EloquentBuilde
$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 @@ -119,7 +122,8 @@ 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: 10 additions & 7 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ 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 @@ -53,7 +55,7 @@ public function linkNodes()
public function toTree($root = false)
{
if ($this->isEmpty()) {
return new static;
return new static();
}

$this->linkNodes();
Expand Down Expand Up @@ -112,9 +114,11 @@ 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 @@ -139,5 +143,4 @@ protected function flattenTree(self $groupedNodes, $parentId)

return $this;
}

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

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 @@ -53,4 +54,4 @@ protected function relationExistenceCondition($hash, $table, $lft, $rgt)
{
return "{$hash}.{$lft} between {$table}.{$lft} + 1 and {$table}.{$rgt}";
}
}
}
13 changes: 6 additions & 7 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.
*/
const LFT = '_lft';
public const LFT = '_lft';

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

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

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

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

/**
* Add default nested set columns to the table. Also create an index.
Expand Down Expand Up @@ -79,5 +79,4 @@ 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