Skip to content

Commit 2cd3e0a

Browse files
committed
PHPCS Fixer, refactored and updated test suite
1 parent 2d7a928 commit 2cd3e0a

35 files changed

Lines changed: 284 additions & 132 deletions

.github/workflows/ci.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,7 @@ jobs:
2828
2929
- name: Install composer dependencies
3030
run: |
31-
composer install --no-scripts
32-
33-
# - name: Prepare Laravel Application
34-
# run: |
35-
# cp .env.ci .env
36-
# php artisan key:generate
31+
composer install --prefer-dist --no-interaction --no-scripts
3732
3833
- name: Run Testsuite
3934
run: vendor/bin/phpunit tests/

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ phpunit.xml
88
.phpunit.result.cache
99
.DS_Store
1010
Thumbs.db
11+
.php_cs.cache

.php_cs

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->exclude('bootstrap/cache')
5+
->exclude('storage')
6+
->exclude('vendor')
7+
->exclude('bower_components')
8+
->exclude('node_modules')
9+
->in(__DIR__)
10+
->name('*.php')
11+
->notName('*.blade.php')
12+
->ignoreDotFiles(true)
13+
->ignoreVCS(true);
14+
15+
return PhpCsFixer\Config::create()
16+
->setFinder($finder)
17+
->setRules([
18+
'@PSR2' => true,
19+
'phpdoc_no_empty_return' => false,
20+
'phpdoc_var_annotation_correct_order' => true,
21+
'array_syntax' => [
22+
'syntax' => 'short',
23+
],
24+
'no_singleline_whitespace_before_semicolons' => true,
25+
'no_extra_blank_lines' => [
26+
'break', 'case', 'continue', 'curly_brace_block', 'default',
27+
'extra', 'parenthesis_brace_block', 'return',
28+
'square_brace_block', 'switch', 'throw', 'use', 'useTrait', 'use_trait',
29+
],
30+
'cast_spaces' => [
31+
'space' => 'single',
32+
],
33+
'concat_space' => [
34+
'spacing' => 'one',
35+
],
36+
'ordered_imports' => [
37+
'sort_algorithm' => 'length',
38+
],
39+
'single_quote' => true,
40+
'lowercase_cast' => true,
41+
'lowercase_static_reference' => true,
42+
'no_empty_phpdoc' => true,
43+
'no_empty_comment' => true,
44+
'array_indentation' => true,
45+
// TODO: This isn't working, causes fixer to error.
46+
// 'increment_style' => ['style' => 'post'],
47+
'short_scalar_cast' => true,
48+
'class_attributes_separation' => [
49+
'elements' => ['const', 'method', 'property'],
50+
],
51+
'no_mixed_echo_print' => [
52+
'use' => 'echo',
53+
],
54+
'no_unused_imports' => true,
55+
'binary_operator_spaces' => [
56+
'default' => 'single_space',
57+
],
58+
'no_empty_statement' => true,
59+
'unary_operator_spaces' => true, // $number ++ becomes $number++
60+
'hash_to_slash_comment' => true, // # becomes //
61+
'standardize_not_equals' => true, // <> becomes !=
62+
'native_function_casing' => true,
63+
'ternary_operator_spaces' => true,
64+
'ternary_to_null_coalescing' => true,
65+
'declare_equal_normalize' => [
66+
'space' => 'single',
67+
],
68+
'function_typehint_space' => true,
69+
'no_leading_import_slash' => true,
70+
'blank_line_before_statement' => [
71+
'statements' => [
72+
'break', 'case', 'continue',
73+
'declare', 'default', 'die',
74+
'do', 'exit', 'for', 'foreach',
75+
'goto', 'if', 'include',
76+
'include_once', 'require', 'require_once',
77+
'return', 'switch', 'throw', 'try', 'while', 'yield',
78+
],
79+
],
80+
'combine_consecutive_unsets' => true,
81+
'method_chaining_indentation' => true,
82+
'no_whitespace_in_blank_line' => true,
83+
'blank_line_after_opening_tag' => true,
84+
'no_trailing_comma_in_list_call' => true,
85+
'list_syntax' => ['syntax' => 'short'],
86+
// public function getTimezoneAttribute( ? Banana $value) becomes public function getTimezoneAttribute(?Banana $value)
87+
'compact_nullable_typehint' => true,
88+
'explicit_string_variable' => true,
89+
'no_leading_namespace_whitespace' => true,
90+
'trailing_comma_in_multiline_array' => true,
91+
'not_operator_with_successor_space' => true,
92+
'object_operator_without_whitespace' => true,
93+
'single_blank_line_before_namespace' => true,
94+
'no_blank_lines_after_class_opening' => true,
95+
'no_blank_lines_after_phpdoc' => true,
96+
'no_whitespace_before_comma_in_array' => true,
97+
'no_trailing_comma_in_singleline_array' => true,
98+
'multiline_whitespace_before_semicolons' => [
99+
'strategy' => 'no_multi_line',
100+
],
101+
'no_multiline_whitespace_around_double_arrow' => true,
102+
'no_useless_return' => true,
103+
'phpdoc_add_missing_param_annotation' => true,
104+
'phpdoc_order' => true,
105+
'phpdoc_scalar' => true,
106+
'phpdoc_separation' => true,
107+
'phpdoc_single_line_var_spacing' => true,
108+
'single_trait_insert_per_statement' => true,
109+
'ordered_class_elements' => [
110+
'order' => [
111+
'use_trait',
112+
'constant',
113+
'property',
114+
'construct',
115+
'public',
116+
'protected',
117+
'private',
118+
],
119+
'sortAlgorithm' => 'none',
120+
],
121+
'return_type_declaration' => [
122+
'space_before' => 'none',
123+
],
124+
])
125+
->setLineEnding("\n");

composer.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
}
1717
],
1818
"require-dev": {
19-
"orchestra/testbench": "^3.8",
20-
"phpunit/phpunit": "^7.5",
19+
"codedungeon/phpunit-result-printer": "^0.26.2",
20+
"orchestra/testing": "^4.0",
21+
"phpunit/phpunit": "^8.3",
2122
"mockery/mockery": "^1.1",
22-
"laravel/nova": "^2.5"
23+
"laravel/nova": "*"
2324
},
2425
"autoload": {
2526
"psr-4": {
@@ -28,7 +29,7 @@
2829
},
2930
"autoload-dev": {
3031
"psr-4": {
31-
"KirschbaumDevelopment\\NovaInlineRelationship\\Tests\\": "tests/"
32+
"Tests\\": "tests/"
3233
}
3334
},
3435
"extra": {

phpunit.xml.dist

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit bootstrap="vendor/autoload.php"
3+
backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
verbose="true"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
processIsolation="false"
11+
stopOnFailure="false"
12+
printerClass="Codedungeon\PHPUnitPrettyResultPrinter\Printer">
13+
<testsuites>
14+
<testsuite name="Nova Inline Relationship Test Suite">
15+
<directory>tests</directory>
16+
</testsuite>
17+
</testsuites>
18+
<filter>
19+
<whitelist>
20+
<directory suffix=".php">src/</directory>
21+
</whitelist>
22+
</filter>
23+
</phpunit>

src/Contracts/RelationshipObservable.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ interface RelationshipObservable
1212
* @param Model $model
1313
* @param $attribute
1414
* @param $value
15+
*
1516
* @return mixed
1617
*/
1718
public function updating(Model $model, $attribute, $value);
@@ -22,6 +23,7 @@ public function updating(Model $model, $attribute, $value);
2223
* @param Model $model
2324
* @param $attribute
2425
* @param $value
26+
*
2527
* @return mixed
2628
*/
2729
public function creating(Model $model, $attribute, $value);
@@ -32,6 +34,7 @@ public function creating(Model $model, $attribute, $value);
3234
* @param Model $model
3335
* @param $attribute
3436
* @param $value
37+
*
3538
* @return mixed
3639
*/
3740
public function created(Model $model, $attribute, $value);

src/NovaInlineRelationship.php

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public function resourceClass(string $class): self
6767
*
6868
* @param mixed $resource
6969
* @param string|null $attribute
70+
*
7071
* @return void
7172
*/
7273
public function resolveForDisplay($resource, $attribute = null)
@@ -103,49 +104,6 @@ public function resolve($resource, $attribute = null)
103104
}
104105
}
105106

106-
/**
107-
* Resolve the fields for the resource.
108-
*
109-
* @param $resource
110-
* @param $attribute
111-
* @param $properties
112-
*/
113-
protected function resolveResourceFields($resource, $attribute, $properties)
114-
{
115-
$this->rules = [$this->getRelationshipRule($attribute, $properties)];
116-
117-
$this->withMeta([
118-
'defaults' => $this->getDefaultsFromProperties($properties)->all(),
119-
'settings' => $properties->all(),
120-
'models' => $this->modelIds(),
121-
'modelKey' => Str::plural(Str::kebab(class_basename(optional($this->value)->first() ?? $resource->{$attribute}()->getRelated()->newInstance()))),
122-
'singularLabel' => Str::title(Str::singular($this->name)),
123-
'pluralLabel' => Str::title(Str::plural($this->name)),
124-
'singular' => $this->isSingularRelationship($resource, $attribute),
125-
'deletable' => $this->isRelationshipDeletable($resource, $attribute),
126-
'addChildAtStart' => $this->requireChild,
127-
]);
128-
129-
$this->updateFieldValue($resource, $attribute, $properties);
130-
}
131-
132-
/**
133-
* Pluck id's from the model or collection.
134-
*
135-
* @return array
136-
*/
137-
protected function modelIds()
138-
{
139-
if ($this->value instanceof Model) {
140-
$models = [$this->value->{$this->value->getKeyName()}];
141-
} elseif ($this->value instanceof Collection && $this->value->isNotEmpty()) {
142-
$key = $this->value->first()->getKeyName();
143-
$models = $this->value->pluck($key)->all();
144-
}
145-
146-
return $models ?? [];
147-
}
148-
149107
/**
150108
* Fetch default values from collection
151109
*
@@ -206,7 +164,7 @@ public function getPropertiesWithMetaForForms($resource, $attribute): Collection
206164
->keyBy('attribute')
207165
->map(function ($value, $key) {
208166
return $this->setMetaFromClass($value, $key);
209-
});;
167+
});
210168
}
211169

212170
/**
@@ -276,6 +234,49 @@ public function getValueFromField(Field $field, NovaInlineRelationshipRequest $r
276234
return $temp->{$attribute} ?? null;
277235
}
278236

237+
/**
238+
* Resolve the fields for the resource.
239+
*
240+
* @param $resource
241+
* @param $attribute
242+
* @param $properties
243+
*/
244+
protected function resolveResourceFields($resource, $attribute, $properties)
245+
{
246+
$this->rules = [$this->getRelationshipRule($attribute, $properties)];
247+
248+
$this->withMeta([
249+
'defaults' => $this->getDefaultsFromProperties($properties)->all(),
250+
'settings' => $properties->all(),
251+
'models' => $this->modelIds(),
252+
'modelKey' => Str::plural(Str::kebab(class_basename(optional($this->value)->first() ?? $resource->{$attribute}()->getRelated()->newInstance()))),
253+
'singularLabel' => Str::title(Str::singular($this->name)),
254+
'pluralLabel' => Str::title(Str::plural($this->name)),
255+
'singular' => $this->isSingularRelationship($resource, $attribute),
256+
'deletable' => $this->isRelationshipDeletable($resource, $attribute),
257+
'addChildAtStart' => $this->requireChild,
258+
]);
259+
260+
$this->updateFieldValue($resource, $attribute, $properties);
261+
}
262+
263+
/**
264+
* Pluck id's from the model or collection.
265+
*
266+
* @return array
267+
*/
268+
protected function modelIds()
269+
{
270+
if ($this->value instanceof Model) {
271+
$models = [$this->value->{$this->value->getKeyName()}];
272+
} elseif ($this->value instanceof Collection && $this->value->isNotEmpty()) {
273+
$key = $this->value->first()->getKeyName();
274+
$models = $this->value->pluck($key)->all();
275+
}
276+
277+
return $models ?? [];
278+
}
279+
279280
/**
280281
* Set Meta Values using Field
281282
*
@@ -439,7 +440,7 @@ protected function getPropertiesFromFields(Collection $fields): Collection
439440
'label' => $value->name,
440441
'options' => $value->meta,
441442
'rules' => $value->rules,
442-
'attribute' => $value->attribute
443+
'attribute' => $value->attribute,
443444
];
444445
});
445446
}
@@ -462,7 +463,6 @@ protected function updateFieldValue($resource, $attribute, Collection $propertie
462463
return $properties->has($key) ? $this->setMetaFromClass($properties->get($key), $key, $value) : null;
463464
})->filter();
464465
});
465-
466466
}
467467

468468
/**

tests/Bill.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace KirschbaumDevelopment\NovaInlineRelationship\Tests;
3+
namespace Tests;
44

55
use Illuminate\Database\Eloquent\Model;
66

tests/Comment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace KirschbaumDevelopment\NovaInlineRelationship\Tests;
3+
namespace Tests;
44

55
use Illuminate\Database\Eloquent\Model;
66

tests/Department.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace KirschbaumDevelopment\NovaInlineRelationship\Tests;
3+
namespace Tests;
44

55
use Illuminate\Database\Eloquent\Model;
66

0 commit comments

Comments
 (0)