Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor publication page validation #843

Merged
merged 230 commits into from
Jan 20, 2023
Merged
Changes from 1 commit
Commits
Show all changes
230 commits
Select commit Hold shift + click to select a range
cedf6e4
Create PublicationPageValidator.php
caendesilva Jan 18, 2023
e4ff2bb
Create PublicationPageValidatorTest.php
caendesilva Jan 18, 2023
85cb32a
Create base class data structure and constructor
caendesilva Jan 18, 2023
c0d7b1c
Make invoke method fluent
caendesilva Jan 18, 2023
d34f291
Create base field validation logic
caendesilva Jan 18, 2023
bb198f1
Implement the validate method
caendesilva Jan 18, 2023
f9ce908
Implement the errors method
caendesilva Jan 18, 2023
0feb182
Fix coverage annotation
caendesilva Jan 18, 2023
7fccc9a
Implement base test method
caendesilva Jan 18, 2023
cc91961
Merge explicit invoker with dynamic static call method in test
caendesilva Jan 18, 2023
a83fceb
Test with invalid fields
caendesilva Jan 18, 2023
8abaa86
Test buffered output
caendesilva Jan 18, 2023
700defe
Convert array to associative to preserve field names
caendesilva Jan 18, 2023
9b29868
Temporarily update expected array
caendesilva Jan 18, 2023
a1fec1e
Add spacing between input and buffer properties
caendesilva Jan 18, 2023
99f244e
Merge validation loop into single validator call
caendesilva Jan 18, 2023
dc59b04
Revert "Temporarily update expected array"
caendesilva Jan 18, 2023
dd363fe
Expect case to be evaluated by validator
caendesilva Jan 18, 2023
24c5035
Flatten buffer for merged loop
caendesilva Jan 18, 2023
adaae58
Inline local variable
caendesilva Jan 18, 2023
49fbe24
Extract method
caendesilva Jan 18, 2023
432b847
Apply fixes from StyleCI
StyleCIBot Jan 18, 2023
b318874
Remove deprecated counters
caendesilva Jan 19, 2023
3685b35
Count using method instead of removed property
caendesilva Jan 19, 2023
4caaefd
Flatten array structure
caendesilva Jan 19, 2023
c2c9eb7
Get publication filelist via glob instead of parsing them
caendesilva Jan 19, 2023
937e3f4
Validate using action
caendesilva Jan 19, 2023
4c58ba4
Add todo
caendesilva Jan 19, 2023
3ec7d7e
Get the errors array
caendesilva Jan 19, 2023
b68c7aa
Buffer array
caendesilva Jan 19, 2023
f960721
Replace local variable initializer with null coalesce
caendesilva Jan 19, 2023
88c1636
Rename local loop variable
caendesilva Jan 19, 2023
ef5bc5d
Inline local variable
caendesilva Jan 19, 2023
431330e
Revert "Buffer array"
caendesilva Jan 19, 2023
de0f25d
Remove unused method validatePublicationField
caendesilva Jan 19, 2023
99c356e
Merge todo code into helper method
caendesilva Jan 19, 2023
6e30a2d
Remove unused imports
caendesilva Jan 19, 2023
32f9339
Flatten array structure
caendesilva Jan 19, 2023
ef0e1f7
Flatten array structure
caendesilva Jan 19, 2023
c4f229c
Count using method instead of removed property
caendesilva Jan 19, 2023
8f73186
Count using method instead of removed property
caendesilva Jan 19, 2023
eb56c26
Create countErrors method
caendesilva Jan 19, 2023
e53b6f3
Create countWarnings method stub
caendesilva Jan 19, 2023
ca1dc00
Convert array to associative
caendesilva Jan 19, 2023
a0946ba
Update countErrors method to match internal data structure
caendesilva Jan 19, 2023
0d60927
Group together counting helpers
caendesilva Jan 19, 2023
89c265f
Update for flattened array structure
caendesilva Jan 19, 2023
7ba74b4
Test with multiple invalid fields
caendesilva Jan 19, 2023
a40d495
Port logic to collect warnings to action
caendesilva Jan 19, 2023
e6be0c9
Remove code comment for clarified warning message
caendesilva Jan 19, 2023
30a94b3
Update todo message
caendesilva Jan 19, 2023
584a1cc
Introduce local variable for repeated operation
caendesilva Jan 19, 2023
bd9aa2b
Introduce local variable for the validator
caendesilva Jan 19, 2023
3f80761
Convert value to multidimensional array
caendesilva Jan 19, 2023
073d6cd
Add array for the warnings
caendesilva Jan 19, 2023
51068d4
Update counter to account for deepened array
caendesilva Jan 19, 2023
8655d08
Implement the countWarnings method
caendesilva Jan 19, 2023
d7cc8f7
Fix warning logic
caendesilva Jan 19, 2023
c683315
Introduce local variable as there's no reason to recompute array in loop
caendesilva Jan 19, 2023
cd3f713
Invert in_array to actually fix warning logic
caendesilva Jan 19, 2023
85e29e7
Do not add warnings for meta fields
caendesilva Jan 19, 2023
c437055
Unset meta field entirely
caendesilva Jan 19, 2023
c765a90
Remove now already evaluated condition
caendesilva Jan 19, 2023
7e3f1e9
Remove counter methods
caendesilva Jan 19, 2023
797027f
Create new counter properties
caendesilva Jan 19, 2023
1ed1c1e
Increment the counters
caendesilva Jan 19, 2023
d0a2c8c
Create internal accessor
caendesilva Jan 19, 2023
d0c5c4c
Update expectations as field counter now counts actual fields in publ…
caendesilva Jan 19, 2023
550eda8
Add more tests for JSON output
caendesilva Jan 19, 2023
a1cf35f
Apply fixes from StyleCI
StyleCIBot Jan 19, 2023
e07ab5a
Change protected visibility of command class helpers to private
caendesilva Jan 19, 2023
9a8be5e
Import used functions
caendesilva Jan 19, 2023
cc70669
Unwrap unnecessary curly braces
caendesilva Jan 19, 2023
231d661
Make method 'void'
caendesilva Jan 19, 2023
1237082
Inline parameter value
caendesilva Jan 19, 2023
9c33d38
Remove PHPDoc comment
caendesilva Jan 19, 2023
f87f01a
Move down helper method
caendesilva Jan 19, 2023
3b01e45
Replace property with local variable
caendesilva Jan 19, 2023
33b4d50
Inline local variable
caendesilva Jan 19, 2023
6cd8c1d
Remove unnecessary parentheses
caendesilva Jan 19, 2023
b06344a
Introduce property for local variable being passed around
caendesilva Jan 19, 2023
df9474c
Buffer array so entry is always present to be shown in output
caendesilva Jan 19, 2023
1ce2e28
Extract method
caendesilva Jan 19, 2023
409783e
Revert "Change protected visibility of command class helpers to private"
caendesilva Jan 19, 2023
1905260
Add type annotation
caendesilva Jan 19, 2023
f0e137c
Apply fixes from StyleCI
StyleCIBot Jan 19, 2023
a5db362
Prefix warnings with 'Warning: '
caendesilva Jan 19, 2023
10ef7fe
Merge warnings with errors for a simple data structure
caendesilva Jan 19, 2023
ecbb5df
Add test for fields with warning and error
caendesilva Jan 19, 2023
b403b8c
Extract helper method
caendesilva Jan 19, 2023
5da0b7c
Inline variable
caendesilva Jan 19, 2023
e9f5ccc
Make verbose option always true to reduce complexity
caendesilva Jan 19, 2023
98f70b1
Inline $verbose property
caendesilva Jan 19, 2023
b2e210c
Unwrap always true conditions
caendesilva Jan 19, 2023
7722ee9
Merge string literal into sprintf body
caendesilva Jan 19, 2023
7c03581
Extract method
caendesilva Jan 19, 2023
cc67ee3
Rename variables to match changed data structure
caendesilva Jan 19, 2023
b0bf282
Update helper method parameters
caendesilva Jan 19, 2023
ac81ecd
Extract method
caendesilva Jan 19, 2023
312ac78
Update for flattened data structure
caendesilva Jan 19, 2023
4234430
Add marker for the field name
caendesilva Jan 19, 2023
dbb108d
Update state logic to use added warning prefix
caendesilva Jan 19, 2023
cb3d458
Rename method argument to results
caendesilva Jan 19, 2023
7935ee9
Split out the array depending on warning prefix
caendesilva Jan 19, 2023
275ba47
Set state depending on count
caendesilva Jan 19, 2023
4cd5876
Use the new warning array
caendesilva Jan 19, 2023
e16d08d
Unwrap duplicate prefix provided by message
caendesilva Jan 19, 2023
99dd477
Display warnings after errors
caendesilva Jan 19, 2023
6ac315e
Revert "Display warnings after errors"
caendesilva Jan 19, 2023
625fcc2
Set evaluated condition to true
caendesilva Jan 19, 2023
f8e4a16
Unwrap loop for flattened array
caendesilva Jan 19, 2023
385a679
Add todo marker
caendesilva Jan 19, 2023
70ba994
Move combining logic to action
caendesilva Jan 19, 2023
4ed9323
Convert warnings array to multidimensional
caendesilva Jan 19, 2023
4194937
Update warning message
caendesilva Jan 19, 2023
0a26d04
Call toArray instead of all to get the associative array
caendesilva Jan 19, 2023
3e34df6
Collect and map array to flatten inner array
caendesilva Jan 19, 2023
816568f
Implode array instead of cutting it off to allow multiple errors
caendesilva Jan 19, 2023
97ee959
Give errors precedence as they might override warnings due to shared key
caendesilva Jan 19, 2023
1f25a1f
Add return annotation
caendesilva Jan 19, 2023
3c41c0b
Update to expect array keys
caendesilva Jan 19, 2023
2f085e8
Inline helper method
caendesilva Jan 19, 2023
39585a2
Create new result loop
caendesilva Jan 19, 2023
d3b66bd
Move up field name output
caendesilva Jan 19, 2023
22fb61f
Fix field state logic
caendesilva Jan 19, 2023
f139eb5
Add marker
caendesilva Jan 19, 2023
7d3dc13
Introduce local variable
caendesilva Jan 19, 2023
2825bb2
Merge foreach loops
caendesilva Jan 19, 2023
07c686e
Revert "Add marker"
caendesilva Jan 19, 2023
10e3db9
Revert "Inline helper method"
caendesilva Jan 19, 2023
e241b3f
Display warning as we probably do not want to show fields passed as t…
caendesilva Jan 19, 2023
9297642
Inline local variable
caendesilva Jan 19, 2023
f764970
Flip '?:'
caendesilva Jan 19, 2023
8823d39
Format ternary call
caendesilva Jan 19, 2023
b22f66f
Introduce local variable
caendesilva Jan 19, 2023
c16990f
Simplify and merge 'if' into method call parameter
caendesilva Jan 19, 2023
ad04fc1
Test with valid field
caendesilva Jan 19, 2023
50812b7
Merge colouring into constant icon values
caendesilva Jan 19, 2023
06df420
Convert unnecessary sprintf call to scalar value
caendesilva Jan 19, 2023
0fd4e2f
Convert 'sprintf()' calls to concatenation
caendesilva Jan 19, 2023
99a3ff4
Shift spacing location
caendesilva Jan 19, 2023
5955e79
Collapse simplified ternary statement
caendesilva Jan 19, 2023
dcb5443
Inline simplified variable
caendesilva Jan 19, 2023
4113c8a
Split out indentation from ternary statement
caendesilva Jan 19, 2023
9ada125
Collapse simplified ternary statement
caendesilva Jan 19, 2023
36f5fb0
Add some code spacing
caendesilva Jan 19, 2023
c869938
Display results for all fields, including those which passed validation
caendesilva Jan 19, 2023
2fd2530
Deprecate internal helper method
caendesilva Jan 19, 2023
d9a728f
Merge in the schema fields so results cover both fields within and ou…
caendesilva Jan 19, 2023
95e820f
Introduce local variable
caendesilva Jan 19, 2023
6b81f9c
Update expected Json output
caendesilva Jan 19, 2023
ad1ea00
Move down location of warning prefix
caendesilva Jan 19, 2023
dd46ce3
Move error prefix to the validator action
caendesilva Jan 19, 2023
c5d44bd
Simplify print logic
caendesilva Jan 19, 2023
988355e
Convert concatenation to 'sprintf()' call
caendesilva Jan 19, 2023
b53221a
Merge string interpolation to 'sprintf()' call
caendesilva Jan 19, 2023
b192e47
Apply fixes from StyleCI
StyleCIBot Jan 19, 2023
24fc383
Expect keyed array
caendesilva Jan 19, 2023
6b36c9a
Update expected message for changed message
caendesilva Jan 19, 2023
f1b4bb1
Revert count based state handlers to booleans
caendesilva Jan 19, 2023
004d8fb
Remove already evaluated condition
caendesilva Jan 19, 2023
ed8da01
Inline subtitle method
caendesilva Jan 19, 2023
93bf549
Move down local variable declarations to their usages
caendesilva Jan 19, 2023
7babceb
Inline local variables
caendesilva Jan 19, 2023
2157720
Bail from method if line is successful
caendesilva Jan 19, 2023
1a05beb
Refactor to invert early return statement into if block
caendesilva Jan 19, 2023
3bf223b
Replace '?:' with if
caendesilva Jan 19, 2023
122585e
Refactor output to a more minimal approach based on the publication t…
caendesilva Jan 19, 2023
d64b5e1
Remove the type prefix
caendesilva Jan 19, 2023
0687b42
Add success output when using verbose option
caendesilva Jan 19, 2023
70a8402
Remove $fieldName parameter as that information is found in the message
caendesilva Jan 19, 2023
a824b3b
Update warning message to match validation errors
caendesilva Jan 19, 2023
e4ac56c
Remove the passed message if there are other messages
caendesilva Jan 19, 2023
f7fad95
Invert control flow to only add variable depending on state instead o…
caendesilva Jan 19, 2023
19ffd17
Update success message to clarify context
caendesilva Jan 19, 2023
d9419a8
Add period to match other messages
caendesilva Jan 19, 2023
e72a828
Revert "Remove the passed message if there are other messages"
caendesilva Jan 19, 2023
6c3cebf
Remove unused foreach variable 'fieldName'
caendesilva Jan 19, 2023
90e5953
Update expected output
caendesilva Jan 19, 2023
edb4e53
Apply fixes from StyleCI
StyleCIBot Jan 19, 2023
871b7d7
Remove file prefix
caendesilva Jan 20, 2023
dfe3f03
Normalize output styling
caendesilva Jan 20, 2023
155b699
Rename internal constants
caendesilva Jan 20, 2023
c252f36
Normalize Unicode icons
caendesilva Jan 20, 2023
a31cb87
Remove unnecessary overlapping style codes already provided by constants
caendesilva Jan 20, 2023
488ac2c
Convert constants to fields
caendesilva Jan 20, 2023
f7cbb2b
Unwrap unnecessary sprintf call
caendesilva Jan 20, 2023
cd503e7
Merge ternary call with subsequent if block
caendesilva Jan 20, 2023
902e994
Extract method
caendesilva Jan 20, 2023
f14a288
Refactor to use return control flow instead of local variable
caendesilva Jan 20, 2023
db782e1
Unwrap else blocks
caendesilva Jan 20, 2023
c47f8db
Replace if statements with match expression
caendesilva Jan 20, 2023
0daa46b
Refactor to bail early instead of buffering state booleans
caendesilva Jan 20, 2023
c981e1f
Split and unwrap 'elseif'
caendesilva Jan 20, 2023
df08481
Move up condition as errors take precedence over warnings
caendesilva Jan 20, 2023
cb8a955
Warnings to need to be buffered as an error might come after it in th…
caendesilva Jan 20, 2023
f5e3352
Refactor to filter the array beforehand
caendesilva Jan 20, 2023
b188d53
Move loop to parameter
caendesilva Jan 20, 2023
379d35e
Inline local variable
caendesilva Jan 20, 2023
6aafd74
Format wrapped line
caendesilva Jan 20, 2023
544dc0d
Extract method
caendesilva Jan 20, 2023
fe1ac72
Rename helper method
caendesilva Jan 20, 2023
5fecf19
Reformat wrapped line
caendesilva Jan 20, 2023
ab0f5c8
Apply fixes from StyleCI
StyleCIBot Jan 20, 2023
4224266
Add test for all output
caendesilva Jan 20, 2023
8d50ead
Extract testing helper for repeated mock code
caendesilva Jan 20, 2023
12924f2
Test with verbose output
caendesilva Jan 20, 2023
262aa7b
Update expected count to match actual count
caendesilva Jan 20, 2023
b21f24f
Replace deprecated method with new helper method for extracted code
caendesilva Jan 20, 2023
a8a6247
Update to expect actual count
caendesilva Jan 20, 2023
45dc38f
Replace counter properties with improved recursive counter function
caendesilva Jan 20, 2023
02423e2
Replace counter incrementor with single static analysis of the results
caendesilva Jan 20, 2023
1694a7f
Inline local variable in simplified method
caendesilva Jan 20, 2023
a75b066
Inline simplified method
caendesilva Jan 20, 2023
5c6e093
Inline local buffering array
caendesilva Jan 20, 2023
84fb642
Get selected type via helper instead of collection
caendesilva Jan 20, 2023
1a86749
Return early as we already know the collection is not empty
caendesilva Jan 20, 2023
e3d1d0b
Extract helper method
caendesilva Jan 20, 2023
291e5d4
Inline local variable
caendesilva Jan 20, 2023
d77d23a
Simplify 'if'
caendesilva Jan 20, 2023
6459397
Revert "Simplify 'if'"
caendesilva Jan 20, 2023
0e35f9b
Revert "Inline local variable"
caendesilva Jan 20, 2023
7c0474d
Revert "Extract helper method"
caendesilva Jan 20, 2023
a9e5993
Reorder helper methods
caendesilva Jan 20, 2023
0a1c375
Apply fixes from StyleCI
StyleCIBot Jan 20, 2023
b6b9eff
Add additional coverage annotation
caendesilva Jan 20, 2023
ea966c6
Merge branch 'master' into refactor-publication-page-validation
caendesilva Jan 20, 2023
3461749
Add override to return static from the invokable validators call methods
caendesilva Jan 20, 2023
cf5de0a
Merge branch 'publications-feature' into refactor-publication-page-va…
caendesilva Jan 20, 2023
4988a6a
Replace warning symbol for one with better console support
caendesilva Jan 20, 2023
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
Prev Previous commit
Next Next commit
Revert "Extract helper method"
This reverts commit e3d1d0b.
caendesilva committed Jan 20, 2023
commit 7c0474de493be28ef7a765e19726363c2f3b812b
Original file line number Diff line number Diff line change
@@ -105,7 +105,10 @@ protected function getPublicationTypesToValidate(): Collection
$name = $this->argument('publicationType');

if (filled($name)) {
return $this->getPublicationTypeFromArgument($publicationTypes, $name);
if (! $publicationTypes->has($name)) {
throw new InvalidArgumentException("Publication type [$name] does not exist");
}
return collect([$name => PublicationType::get($name)]);
}

if ($publicationTypes->isEmpty()) {
@@ -115,14 +118,6 @@ protected function getPublicationTypesToValidate(): Collection
return $publicationTypes;
}

protected function getPublicationTypeFromArgument(Collection $publicationTypes, string $name): Collection
{
if (!$publicationTypes->has($name)) {
throw new InvalidArgumentException("Publication type [$name] does not exist");
}
return collect([$name => PublicationType::get($name)]);
}

protected function displayResults(): void
{
foreach ($this->results as $publicationTypeName => $publications) {