From d06ea0e15bc15c4c03e56ef4d9e293f630b125be Mon Sep 17 00:00:00 2001 From: envomer Date: Thu, 12 Aug 2021 10:29:25 +0200 Subject: [PATCH 1/6] Add PSR-4 namespacing --- .gitignore | 1 + composer.json | 4 +--- spec/elements/empty.spec.php | 2 +- spec/elements/field.spec.php | 2 +- spec/elements/fieldset.spec.php | 8 ++++---- spec/elements/lazy_construction.spec.php | 10 +++++----- spec/elements/list.spec.php | 4 ++-- spec/elements/section.spec.php | 4 ++-- .../analysis/duplicate_fieldset_entry_name.spec.php | 2 +- spec/errors/analysis/fieldset_entry_in_field.spec.php | 2 +- spec/errors/analysis/fieldset_entry_in_list.spec.php | 2 +- spec/errors/analysis/list_item_in_field.spec.php | 2 +- spec/errors/analysis/list_item_in_fieldset.spec.php | 2 +- .../analysis/missing_element_for_continuation.spec.php | 2 +- .../analysis/missing_name_for_fieldset_entry.spec.php | 2 +- .../analysis/missing_name_for_list_item.spec.php | 2 +- .../analysis/section_hierarchy_layer_skip.spec.php | 2 +- spec/errors/error.spec.php | 2 +- spec/errors/parse_error.spec.php | 4 ++-- .../resolution/copying_block_into_fieldset.spec.php | 2 +- .../errors/resolution/copying_block_into_list.spec.php | 2 +- .../resolution/copying_block_into_section.spec.php | 2 +- .../resolution/copying_field_into_fieldset.spec.php | 2 +- .../errors/resolution/copying_field_into_list.spec.php | 2 +- .../resolution/copying_field_into_section.spec.php | 2 +- .../resolution/copying_fieldset_into_field.spec.php | 2 +- .../resolution/copying_fieldset_into_list.spec.php | 2 +- .../resolution/copying_fieldset_into_section.spec.php | 2 +- .../errors/resolution/copying_list_into_field.spec.php | 2 +- .../resolution/copying_list_into_fieldset.spec.php | 2 +- .../resolution/copying_list_into_section.spec.php | 2 +- .../resolution/copying_section_into_empty.spec.php | 2 +- .../resolution/copying_section_into_field.spec.php | 2 +- .../resolution/copying_section_into_fieldset.spec.php | 2 +- .../resolution/copying_section_into_list.spec.php | 2 +- spec/errors/resolution/cyclic_dependency.spec.php | 2 +- .../resolution/multiple_templates_found.spec.php | 2 +- spec/errors/resolution/template_not_found.spec.php | 2 +- spec/errors/tokenization/invalid_line.spec.php | 2 +- spec/errors/tokenization/unterminated_block.spec.php | 2 +- .../tokenization/unterminated_escaped_name.spec.php | 2 +- spec/errors/validation_error.spec.php | 4 ++-- spec/loaders/bootstrapping.spec.php | 8 ++++---- spec/matchers/ToMatchErrorSnapshot.php | 2 +- spec/parse.spec.php | 2 +- spec/util.php | 2 +- src/{elements => Elements}/EmptyElement.php | 5 +++-- src/{elements => Elements}/Field.php | 6 +++--- src/{elements => Elements}/Fieldset.php | 6 ++++-- src/{elements => Elements}/ListElement.php | 8 +++++--- src/{elements => Elements}/Section.php | 9 +++++++-- src/{errors => Errors}/Analysis.php | 2 +- src/{errors => Errors}/Error.php | 2 +- src/{errors => Errors}/ParseError.php | 4 +++- src/{errors => Errors}/Resolution.php | 2 +- src/{errors => Errors}/Tokenization.php | 2 +- src/{errors => Errors}/Validation.php | 4 ++-- src/{errors => Errors}/ValidationError.php | 4 +++- src/Parser.php | 10 +++++----- src/{reporters => Reporters}/HTML.php | 0 src/{reporters => Reporters}/Reporter.php | 0 src/{reporters => Reporters}/Terminal.php | 0 src/{reporters => Reporters}/Text.php | 0 63 files changed, 99 insertions(+), 86 deletions(-) rename src/{elements => Elements}/EmptyElement.php (92%) rename src/{elements => Elements}/Field.php (98%) rename src/{elements => Elements}/Fieldset.php (97%) rename src/{elements => Elements}/ListElement.php (95%) rename src/{elements => Elements}/Section.php (98%) rename src/{errors => Errors}/Analysis.php (99%) rename src/{errors => Errors}/Error.php (97%) rename src/{errors => Errors}/ParseError.php (60%) rename src/{errors => Errors}/Resolution.php (99%) rename src/{errors => Errors}/Tokenization.php (98%) rename src/{errors => Errors}/Validation.php (99%) rename src/{errors => Errors}/ValidationError.php (61%) rename src/{reporters => Reporters}/HTML.php (100%) rename src/{reporters => Reporters}/Reporter.php (100%) rename src/{reporters => Reporters}/Terminal.php (100%) rename src/{reporters => Reporters}/Text.php (100%) diff --git a/.gitignore b/.gitignore index 2084e22..ca44bd2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /vendor/ /coverage.json /composer.phar +.idea diff --git a/composer.json b/composer.json index fc9f5c5..b6ca7a1 100644 --- a/composer.json +++ b/composer.json @@ -8,9 +8,7 @@ ], "autoload": { "psr-4": { - "Eno\\": ["src", "src/elements/", "src/errors/"], - "Eno\\Errors\\": "src/errors", - "Eno\\Reporters\\": "src/reporters" + "Eno\\": "src" } }, "autoload-dev": { diff --git a/spec/elements/empty.spec.php b/spec/elements/empty.spec.php index 9fd0a3d..94af34e 100644 --- a/spec/elements/empty.spec.php +++ b/spec/elements/empty.spec.php @@ -1,6 +1,6 @@ result)->toBeAnInstanceOf('Eno\\Field'); + expect($this->result)->toBeAnInstanceOf('Eno\\Elements\\Field'); }); it('returns the right element', function() { @@ -168,7 +168,7 @@ describe("with [ 'element' => true ]", function() { it('returns the element', function() { $this->result = $this->fieldset->entry('eno', [ 'element' => true ]); - expect($this->result)->toBeAnInstanceOf('Eno\\Field'); + expect($this->result)->toBeAnInstanceOf('Eno\\Elements\\Field'); }); }); @@ -179,7 +179,7 @@ }); it('returns the element', function() { - expect($this->result['element'])->toBeAnInstanceOf('Eno\\Field'); + expect($this->result['element'])->toBeAnInstanceOf('Eno\\Elements\\Field'); }); it('returns the value', function() { diff --git a/spec/elements/lazy_construction.spec.php b/spec/elements/lazy_construction.spec.php index b611cf7..504e31d 100644 --- a/spec/elements/lazy_construction.spec.php +++ b/spec/elements/lazy_construction.spec.php @@ -1,6 +1,6 @@ fieldset)->toBeAnInstanceOf('Eno\\Fieldset'); + expect($this->fieldset)->toBeAnInstanceOf('Eno\\Elements\\Fieldset'); }); it('returns a fieldset with enforceAllElements disabled', function() { @@ -37,7 +37,7 @@ }); it('returns a fieldset as first element', function() { - expect($this->fieldsets[0])->toBeAnInstanceOf('Eno\\Fieldset'); + expect($this->fieldsets[0])->toBeAnInstanceOf('Eno\\Elements\\Fieldset'); }); it('returns a fieldset with enforceAllElements disabled', function() { @@ -63,7 +63,7 @@ }); it('returns a field as first element', function() { - expect($this->fields[0])->toBeAnInstanceOf('Eno\\Field'); + expect($this->fields[0])->toBeAnInstanceOf('Eno\\Elements\\Field'); }); }); @@ -76,6 +76,6 @@ }); it('returns a list as first element', function() { - expect($this->lists[0])->toBeAnInstanceOf('Eno\\ListElement'); + expect($this->lists[0])->toBeAnInstanceOf('Eno\\Elements\\ListElement'); }); }); diff --git a/spec/elements/list.spec.php b/spec/elements/list.spec.php index 7827f25..b792158 100644 --- a/spec/elements/list.spec.php +++ b/spec/elements/list.spec.php @@ -1,6 +1,6 @@ result as $item) { - expect($item['element'])->toBeAnInstanceOf('Eno\\Field'); + expect($item['element'])->toBeAnInstanceOf('Eno\\Elements\\Field'); } }); diff --git a/spec/elements/section.spec.php b/spec/elements/section.spec.php index 516b702..efb1c21 100644 --- a/spec/elements/section.spec.php +++ b/spec/elements/section.spec.php @@ -1,6 +1,6 @@ result as $element) { - expect($element)->toBeAnInstanceOf('Eno\\Field'); + expect($element)->toBeAnInstanceOf('Eno\\Elements\\Field'); } }); }); diff --git a/spec/errors/analysis/duplicate_fieldset_entry_name.spec.php b/spec/errors/analysis/duplicate_fieldset_entry_name.spec.php index 922f71b..c1f9c6f 100644 --- a/spec/errors/analysis/duplicate_fieldset_entry_name.spec.php +++ b/spec/errors/analysis/duplicate_fieldset_entry_name.spec.php @@ -1,6 +1,6 @@ error->cursor)->toEqual($this->cursor); }); - it('is generically catchable as an Eno\\Error when thrown', function() { + it('is generically catchable as an Eno\\Errors\\Error when thrown', function() { $caught = false; try { diff --git a/spec/errors/resolution/copying_block_into_fieldset.spec.php b/spec/errors/resolution/copying_block_into_fieldset.spec.php index a94f2c4..9dfa283 100644 --- a/spec/errors/resolution/copying_block_into_fieldset.spec.php +++ b/spec/errors/resolution/copying_block_into_fieldset.spec.php @@ -1,6 +1,6 @@ error->cursor)->toEqual($this->cursor); }); - it('is generically catchable as an Eno\\Error when thrown', function() { + it('is generically catchable as an Eno\\Errors\\Error when thrown', function() { $caught = false; try { diff --git a/spec/loaders/bootstrapping.spec.php b/spec/loaders/bootstrapping.spec.php index 656367a..7966a71 100644 --- a/spec/loaders/bootstrapping.spec.php +++ b/spec/loaders/bootstrapping.spec.php @@ -37,7 +37,7 @@ it('passes them on', function() { $this->result = $this->ratings->number('excellent', [ 'with_element' => true ]); - expect($this->result['element'])->toBeAnInstanceOf('Eno\\Field'); + expect($this->result['element'])->toBeAnInstanceOf('Eno\\Elements\\Field'); expect($this->result['value'])->toBe(1); }); }); @@ -57,7 +57,7 @@ $items = $this->color_list->colorItems([ 'with_elements' => true ]); foreach($items as $item) { - expect($item['element'])->toBeAnInstanceOf('Eno\\Field'); + expect($item['element'])->toBeAnInstanceOf('Eno\\Elements\\Field'); expect($item['value'])->toBeA('string'); } }); @@ -74,7 +74,7 @@ it('passes them on', function() { $this->result = $this->document->email('email', [ 'with_element' => true ]); - expect($this->result['element'])->toBeAnInstanceOf('Eno\\Field'); + expect($this->result['element'])->toBeAnInstanceOf('Eno\\Elements\\Field'); expect($this->result['value'])->toEqual('jane.doe@eno-lang.org'); }); }); @@ -90,7 +90,7 @@ $items = $this->document->colorList('colors', [ 'with_elements' => true ]); foreach($items as $item) { - expect($item['element'])->toBeAnInstanceOf('Eno\\Field'); + expect($item['element'])->toBeAnInstanceOf('Eno\\Elements\\Field'); expect($item['value'])->toBeA('string'); } }); diff --git a/spec/matchers/ToMatchErrorSnapshot.php b/spec/matchers/ToMatchErrorSnapshot.php index 06de463..a86d54f 100644 --- a/spec/matchers/ToMatchErrorSnapshot.php +++ b/spec/matchers/ToMatchErrorSnapshot.php @@ -1,7 +1,7 @@ value(Closure::fromCallable(['Eno\\Loaders', $function_name]), ...$arguments); } else { - throw new BadMethodCallException("Call to undefined method Eno\\Field::{$function_name}()"); + throw new BadMethodCallException("Call to undefined method Eno\\Elements\\Field::{$function_name}()"); } } diff --git a/src/elements/Fieldset.php b/src/Elements/Fieldset.php similarity index 97% rename from src/elements/Fieldset.php rename to src/Elements/Fieldset.php index 72e84c1..2e3bfdd 100644 --- a/src/elements/Fieldset.php +++ b/src/Elements/Fieldset.php @@ -1,6 +1,8 @@ entry($name, Closure::fromCallable(['Eno\\Loaders', $function_name]), ...$optional); } else { - throw new BadMethodCallException("Call to undefined method Eno\\Fieldset::{$function_name}()"); + throw new BadMethodCallException("Call to undefined method Eno\\Elements\\Fieldset::{$function_name}()"); } } diff --git a/src/elements/ListElement.php b/src/Elements/ListElement.php similarity index 95% rename from src/elements/ListElement.php rename to src/Elements/ListElement.php index 9566640..b53b6d7 100644 --- a/src/elements/ListElement.php +++ b/src/Elements/ListElement.php @@ -1,7 +1,9 @@ items(Closure::fromCallable(['Eno\\Loaders', $function_name]), ...$arguments); } else { - throw new BadMethodCallException("Call to undefined method Eno\\Section::{$function_name}()"); + throw new BadMethodCallException("Call to undefined method Eno\\Elements\\Section::{$function_name}()"); } } diff --git a/src/elements/Section.php b/src/Elements/Section.php similarity index 98% rename from src/elements/Section.php rename to src/Elements/Section.php index 2b46c71..fdcc302 100644 --- a/src/elements/Section.php +++ b/src/Elements/Section.php @@ -1,10 +1,15 @@ list($name, $loader, ...$optional); } } else { - throw new BadMethodCallException("Call to undefined method Eno\\Section::{$function_name}()"); + throw new BadMethodCallException("Call to undefined method Eno\\Elements\\Section::{$function_name}()"); } } diff --git a/src/errors/Analysis.php b/src/Errors/Analysis.php similarity index 99% rename from src/errors/Analysis.php rename to src/Errors/Analysis.php index a0b38ab..2d69057 100644 --- a/src/errors/Analysis.php +++ b/src/Errors/Analysis.php @@ -1,7 +1,7 @@ subinstructions as $subinstruction) { $result = array_merge($result, deepExpandInstruction($subinstruction)); } diff --git a/src/errors/ValidationError.php b/src/Errors/ValidationError.php similarity index 61% rename from src/errors/ValidationError.php rename to src/Errors/ValidationError.php index c056514..d20b1e7 100644 --- a/src/errors/ValidationError.php +++ b/src/Errors/ValidationError.php @@ -1,5 +1,7 @@ 'en', - 'reporter' => new Reporters\Text, - 'source_label' => null, - 'zero_indexing' => false + 'locale' => 'en', + 'reporter' => new Reporters\Text, + 'source_label' => null, + 'zero_indexing' => false ]; $options = array_merge($default_options, $options); diff --git a/src/reporters/HTML.php b/src/Reporters/HTML.php similarity index 100% rename from src/reporters/HTML.php rename to src/Reporters/HTML.php diff --git a/src/reporters/Reporter.php b/src/Reporters/Reporter.php similarity index 100% rename from src/reporters/Reporter.php rename to src/Reporters/Reporter.php diff --git a/src/reporters/Terminal.php b/src/Reporters/Terminal.php similarity index 100% rename from src/reporters/Terminal.php rename to src/Reporters/Terminal.php diff --git a/src/reporters/Text.php b/src/Reporters/Text.php similarity index 100% rename from src/reporters/Text.php rename to src/Reporters/Text.php From e36ad4d08a17b471f1a60f5a5e14418498892781 Mon Sep 17 00:00:00 2001 From: envomer Date: Thu, 12 Aug 2021 10:31:34 +0200 Subject: [PATCH 2/6] Add github workflow --- .github/workflows/main.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..618a146 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,20 @@ +name: Main + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + tests: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Install Dependencies + run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist + + - name: Test (using kahlan) + run: ./vendor/bin/kahlan \ No newline at end of file From e5a42e1c52eab4526bde17c71fe5a34a73741984 Mon Sep 17 00:00:00 2001 From: envomer Date: Thu, 12 Aug 2021 10:41:00 +0200 Subject: [PATCH 3/6] Fix breaking tests #1 --- src/Elements/Field.php | 2 +- src/Elements/Section.php | 1 + src/analyzer.php | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Elements/Field.php b/src/Elements/Field.php index 794643a..777e1e6 100644 --- a/src/Elements/Field.php +++ b/src/Elements/Field.php @@ -157,7 +157,7 @@ public function value(...$optional) { if($this->value !== null) { if($loader) { try { - $info = new ReflectionFunction($loader); + $info = new \ReflectionFunction($loader); switch ($info->getNumberOfParameters()) { case 3: diff --git a/src/Elements/Section.php b/src/Elements/Section.php index fdcc302..0edda0d 100644 --- a/src/Elements/Section.php +++ b/src/Elements/Section.php @@ -1,6 +1,7 @@ unresolved_instructions[] = $instruction; } From f0baa5808a1fafdc3a598a4e615e23a1d8840319 Mon Sep 17 00:00:00 2001 From: envomer Date: Thu, 12 Aug 2021 10:43:09 +0200 Subject: [PATCH 4/6] Fix breaking tests #2 --- src/analyzer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/analyzer.php b/src/analyzer.php index 555d42b..3f1e361 100644 --- a/src/analyzer.php +++ b/src/analyzer.php @@ -79,7 +79,7 @@ function analyze(stdClass $context) : void { $context->unresolved_instructions[] = $instruction; } - if(!array_key_exists('template', $instruction) || $instruction->name !== $instruction->template) { + if(!property_exists($instruction, 'template') || $instruction->name !== $instruction->template) { if(array_key_exists($instruction->name, $context->template_index)) { $context->template_index[$instruction->name][] = $instruction; } else { From 9d76678fb108d87b38f41fd55d24f10943fe9d7e Mon Sep 17 00:00:00 2001 From: envomer Date: Thu, 12 Aug 2021 11:24:57 +0200 Subject: [PATCH 5/6] Remove unnecessary imports --- src/Errors/ParseError.php | 2 -- src/Errors/ValidationError.php | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/Errors/ParseError.php b/src/Errors/ParseError.php index b2bd109..98bf740 100644 --- a/src/Errors/ParseError.php +++ b/src/Errors/ParseError.php @@ -2,6 +2,4 @@ namespace Eno\Errors; -use Eno\Errors\Error; - class ParseError extends Error { } diff --git a/src/Errors/ValidationError.php b/src/Errors/ValidationError.php index d20b1e7..8f136f5 100644 --- a/src/Errors/ValidationError.php +++ b/src/Errors/ValidationError.php @@ -2,6 +2,4 @@ namespace Eno\Errors; -use Eno\Errors\Error; - class ValidationError extends Error { } From c6f511b6b415144ac393fba501f686c5775a9da3 Mon Sep 17 00:00:00 2001 From: envomer Date: Thu, 12 Aug 2021 11:28:28 +0200 Subject: [PATCH 6/6] Add spacing --- .github/workflows/main.yml | 2 +- src/Elements/Section.php | 1 - src/Errors/Analysis.php | 5 ++--- src/Errors/Error.php | 4 +++- src/Errors/Resolution.php | 3 ++- src/Errors/Tokenization.php | 5 +++-- src/Errors/Validation.php | 5 +++-- 7 files changed, 14 insertions(+), 11 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 618a146..943706f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,4 +17,4 @@ jobs: run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist - name: Test (using kahlan) - run: ./vendor/bin/kahlan \ No newline at end of file + run: ./vendor/bin/kahlan diff --git a/src/Elements/Section.php b/src/Elements/Section.php index 0edda0d..eb6ef45 100644 --- a/src/Elements/Section.php +++ b/src/Elements/Section.php @@ -10,7 +10,6 @@ use Eno\Elements\Fieldset; use Eno\Elements\ListElement; use \stdClass; -use const Eno\element; // TODO: Here and elsewhere - declare private properties private // (And use reflection API in specs to still test private properties where needed) diff --git a/src/Errors/Analysis.php b/src/Errors/Analysis.php index 2d69057..178363b 100644 --- a/src/Errors/Analysis.php +++ b/src/Errors/Analysis.php @@ -1,11 +1,10 @@ messages['analysis']['fieldset_entry_in_field']( $entry_instruction->line + $context->indexing diff --git a/src/Errors/Error.php b/src/Errors/Error.php index c8666bb..4a5801a 100644 --- a/src/Errors/Error.php +++ b/src/Errors/Error.php @@ -1,9 +1,11 @@ messages['resolution']['copying_block_into_fieldset']( $instruction->line + $context->indexing diff --git a/src/Errors/Tokenization.php b/src/Errors/Tokenization.php index 1a9c5d7..fcaecb3 100644 --- a/src/Errors/Tokenization.php +++ b/src/Errors/Tokenization.php @@ -1,10 +1,11 @@ messages['validation']['exact_count_not_met']( $instruction->name,