diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..943706f --- /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 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}()"); } } @@ -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/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 99% rename from src/elements/Section.php rename to src/Elements/Section.php index 2b46c71..eb6ef45 100644 --- a/src/elements/Section.php +++ b/src/Elements/Section.php @@ -1,9 +1,14 @@ 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..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 similarity index 93% rename from src/errors/Error.php rename to src/Errors/Error.php index 54aa657..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 similarity index 98% rename from src/errors/Tokenization.php rename to src/Errors/Tokenization.php index f259056..fcaecb3 100644 --- a/src/errors/Tokenization.php +++ b/src/Errors/Tokenization.php @@ -1,10 +1,11 @@ subinstructions as $subinstruction) { $result = array_merge($result, deepExpandInstruction($subinstruction)); } @@ -30,7 +30,8 @@ function expandInstructions(array $instructions) : array { return $result; } -class Validation { +class Validation +{ public static function exactCountNotMet(stdClass $context, stdClass $instruction, int $exact_count) : ValidationError { $message = $context->messages['validation']['exact_count_not_met']( $instruction->name, diff --git a/src/errors/ValidationError.php b/src/Errors/ValidationError.php similarity index 76% rename from src/errors/ValidationError.php rename to src/Errors/ValidationError.php index c056514..8f136f5 100644 --- a/src/errors/ValidationError.php +++ b/src/Errors/ValidationError.php @@ -1,5 +1,5 @@ '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 diff --git a/src/analyzer.php b/src/analyzer.php index de02450..3f1e361 100644 --- a/src/analyzer.php +++ b/src/analyzer.php @@ -75,11 +75,11 @@ function analyze(stdClass $context) : void { $last_continuable_instruction = $instruction; $last_name_instruction = $instruction; - if(array_key_exists('template', $instruction)) { + if(property_exists($instruction, 'template')) { $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 {