Skip to content

Commit

Permalink
Merge branch 'php-8'
Browse files Browse the repository at this point in the history
  • Loading branch information
Loïc Faugeron committed Aug 13, 2024
2 parents 06fc9d8 + 55b30b2 commit 34d0c08
Show file tree
Hide file tree
Showing 17 changed files with 209 additions and 196 deletions.
20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

64 changes: 45 additions & 19 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,45 +19,71 @@ Here's some tips to make you the best contributor ever:
## Standard code

Use [PHP CS fixer](http://cs.sensiolabs.org/) to make your code compliant with
Memio TwigTemplateEngine's coding standards:
Memio's coding standards:

./vendor/bin/php-cs-fixer fix --config=sf23 .
```console
$ ./vendor/bin/php-cs-fixer fix .
```

## Specifications

Memio TwigTemplateEngine drives its development using [phpspec](http://www.phpspec.net/):
Memio drives its development using [phpspec](http://www.phpspec.net/).

# Generate the specification class:
phpspec describe 'Memio\Memio\MyNewClass'
First bootstrap the code for the Specification:

# Customize the specification class:
$EDITOR tests/spec/Memio/TwigTemplateEngine/MyNewClass.php
```console
$ phpspec describe 'Memio\Memio\MyNewUseCase'
```

# Generate the specified class:
phpspec run
Next, write the actual code of the Specification:

# Customize the class:
$EDITOR src/Memio/TwigTemplateEngine/MyNewClass.php
```console
$ $EDITOR spec/Memio/TwigTemplateEngine/MyNewUseCase.php
```

phpspec run # Should be green!
Then bootstrap the code for the corresponding Use Case:

```console
$ phpspec run
```

Follow that by writing the actual code of the Use Case:

```console
$ $EDITOR src/Memio/TwigTemplateEngine/MyNewUseCase.php
```

Finally run the specification:

```console
$ phpspec run
```

Results should be green!

## Keeping your fork up-to-date

To keep your fork up-to-date, you should track the upstream (original) one
using the following command:

git remote add upstream https://github.com/memio/twig-template-engine.git
```console
$ git remote add upstream https://github.com/memio/twig-template-engine.git
```

Then get the upstream changes:

git checkout master
git pull --rebase origin master
git pull --rebase upstream master
git checkout <your-branch>
git rebase master
```console
git checkout main
git pull --rebase origin main
git pull --rebase upstream main
git checkout <your-branch>
git rebase main
```

Finally, publish your changes:

git push -f origin <your-branch>
```console
$ git push -f origin <your-branch>
```

Your pull request will be automatically updated.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2015 Loïc Faugeron
Copyright (c) 2015-2024 Loïc Faugeron

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Memio's TwigTemplateEngine [![SensioLabsInsight](https://insight.sensiolabs.com/projects/d36f6c6e-c3c1-44f5-9573-c76ad99c0253/mini.png)](https://insight.sensiolabs.com/projects/d36f6c6e-c3c1-44f5-9573-c76ad99c0253) [![Travis CI](https://travis-ci.org/memio/twig-template-engine.png)](https://travis-ci.org/memio/twig-template-engine)
# Memio's TwigTemplateEngine

Memio is a highly opinionated PHP code generator library. It is composed of small
independent packages, one being `PrettyPrinter`: the actual code generator.
Expand All @@ -16,7 +16,9 @@ This package, `TwigTemplateEngine`, provides an implementation and templates for

Install it using [Composer](https://getcomposer.org/download):

composer require memio/twig-template-engine:^2.0
```console
composer require memio/twig-template-engine:^2.0
```

## Example

Expand Down Expand Up @@ -73,7 +75,7 @@ echo $prettyPrinter->generateCode($myService);

With this simple example, we get the following output:

```
```php
<?php

namespace Vendor\Project;
Expand All @@ -96,13 +98,15 @@ Have a look at [the main respository](http://github.com/memio/memio) to discover
Memio uses [phpspec](http://phpspec.net/), which means the tests also provide the documentation.
Not convinced? Then clone this repository and run the following commands:

composer install
./vendor/bin/phpspec run -n -f pretty
```console
$ composer install
$ ./vendor/bin/phpspec run -n -f pretty
```

You can see the current and past versions using one of the following:

* the `git tag` command
* the [releases page on Github](https://github.com/memio/memio/releases)
* the [releases page on Github](https://github.com/memio/twig-template-engine/releases)
* the file listing the [changes between versions](CHANGELOG.md)

And finally some meta documentation:
Expand Down
4 changes: 2 additions & 2 deletions VERSIONING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ API of this project.
The branching is inspired by [@jbenet](https://github.com/jbenet)
[simple git branching model](https://gist.github.com/jbenet/ee6c9ac48068889b0912):

> 1. `master` must always be deployable.
> 1. `main` must always be deployable.
> 2. **all changes** are made through feature branches (pull-request + merge)
> 3. rebase to avoid/resolve conflicts; merge in to `master`
> 3. rebase to avoid/resolve conflicts; merge in to `main`
13 changes: 4 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,13 @@
"Memio\\TwigTemplateEngine\\Config\\": "config"
}},
"require": {
"memio/model": "^2.0",
"memio/pretty-printer": "^2.0",
"php": "^7.0",
"memio/model": "^3.0",
"memio/pretty-printer": "^3.0",
"php": "^7.2 || ^8.0",
"twig/twig": "^1.18 || ^2.0 || ^3.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.10",
"phpspec/phpspec": "^4.3"
},
"extra": {
"branch-alias": {
"dev-master": "2.1-dev"
}
"phpspec/phpspec": "^6.1 || ^7.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,34 @@

namespace spec\Memio\TwigTemplateEngine\TwigExtension\Line;

use Memio\Model\Constant;
use Memio\Model\Contract;
use Memio\Model\Method;
use Memio\TwigTemplateEngine\TwigExtension\Line\LineStrategy;
use Memio\TwigTemplateEngine\TwigExtension\Line\ContractLineStrategy;
use PhpSpec\ObjectBehavior;

class ContractLineStrategySpec extends ObjectBehavior
{
const CONSTANT_BLOCK = 'constants';

function it_is_a_line_strategy()
{
$this->shouldImplement(LineStrategy::class);
}

function it_supports_contracts(Contract $contract)
function it_supports_contracts()
{
$contract = (new Contract('Memio\PrettyPrinter\TemplateEngine'));

$this->supports($contract)->shouldBe(true);
}

function it_needs_line_after_constants_if_contract_has_both_constants_and_methods(
Contract $contract
) {
$contract->allConstants()->willReturn([1]);
$contract->allMethods()->willReturn([2]);
function it_needs_an_empty_line_after_constants_if_it_also_has_methods()
{
$contract = (new Contract('Memio\PrettyPrinter\TemplateEngine'))
->addConstant(new Constant('CONSTANT_ONE', 1))
->addMethod(new Method('methodOne'))
;

$this->needsLineAfter($contract, self::CONSTANT_BLOCK)->shouldBe(true);
$this->needsLineAfter($contract, ContractLineStrategy::CONSTANTS_BLOCK)->shouldBe(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,31 @@
namespace spec\Memio\TwigTemplateEngine\TwigExtension\Line;

use Memio\Model\File;
use Memio\Model\FullyQualifiedName;
use Memio\TwigTemplateEngine\TwigExtension\Line\FileLineStrategy;
use Memio\TwigTemplateEngine\TwigExtension\Line\LineStrategy;
use PhpSpec\ObjectBehavior;

class FileLineStrategySpec extends ObjectBehavior
{
const IMPORT_BLOCK = 'fully_qualified_names';

function it_is_a_line_strategy()
{
$this->shouldImplement(LineStrategy::class);
}

function it_supports_files(File $file)
function it_supports_files()
{
$file = new File('src/Memio/Model/Contract.php');

$this->supports($file)->shouldBe(true);
}

function it_needs_line_after_fully_qualified_names_if_file_has_fully_qualified_names(
File $file
) {
$file->allFullyQualifiedNames()->willReturn([1]);
function it_needs_an_empty_line_after_use_statements()
{
$file = (new File('src/Memio/Model/Contract.php'))
->addFullyQualifiedName(new FullyQualifiedName('Memio\Model\Phpdoc\StructurePhpdoc'))
;

$this->needsLineAfter($file, self::IMPORT_BLOCK)->shouldBe(true);
$this->needsLineAfter($file, FileLineStrategy::USE_STATEMENTS_BLOCK)->shouldBe(true);
}
}
26 changes: 13 additions & 13 deletions spec/Memio/TwigTemplateEngine/TwigExtension/Line/LineSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,32 @@

class LineSpec extends ObjectBehavior
{
const BLOCK = 'constants';
const STRATEGY_RETURN = true;

function let(LineStrategy $lineStrategy)
{
$this->add($lineStrategy);
}

function it_executes_the_first_strategy_that_supports_given_model(
Argument $model,
LineStrategy $lineStrategy
) {
$this->add($lineStrategy);

$model = new Argument('string', 'filename');
$block = 'arguments';
$strategyReturn = true;

$lineStrategy->supports($model)->willReturn(true);
$lineStrategy->needsLineAfter($model, self::BLOCK)->willReturn(self::STRATEGY_RETURN);
$lineStrategy->needsLineAfter($model, $block)->willReturn($strategyReturn);

$this->needsLineAfter($model, self::BLOCK)->shouldBe(self::STRATEGY_RETURN);
$this->needsLineAfter($model, $block)->shouldBe($strategyReturn);
}

function it_fails_when_no_strategy_supports_given_model(
Argument $model,
LineStrategy $lineStrategy
) {
$this->add($lineStrategy);

$model = new Argument('string', 'filename');

$lineStrategy->supports($model)->willReturn(false);

$this->shouldThrow(
InvalidArgumentException::class
)->duringNeedsLineAfter($model, self::BLOCK);
)->duringNeedsLineAfter($model, 'arguments');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,52 +26,39 @@ function it_is_a_line_strategy()
$this->shouldImplement(LineStrategy::class);
}

function it_supports_method_phpdocs(MethodPhpdoc $methodPhpdoc)
function it_supports_method_phpdocs()
{
$methodPhpdoc = new MethodPhpdoc();

$this->supports($methodPhpdoc)->shouldBe(true);
}

function it_needs_line_after_description_if_it_has_any_other_tag(
Description $description,
DeprecationTag $deprecationTag,
MethodPhpdoc $methodPhpdoc
) {
$methodPhpdoc->getApiTag()->willReturn(null);
$methodPhpdoc->getDescription()->willReturn($description);
$methodPhpdoc->getDeprecationTag()->willReturn($deprecationTag);
$methodPhpdoc->getParameterTags()->willReturn([]);
$methodPhpdoc->getReturnTag()->willReturn(null);
$methodPhpdoc->getThrowTags()->willReturn([]);
function it_needs_a_new_line_after_description_if_it_has_any_other_tag()
{
$methodPhpdoc = (new MethodPhpdoc())
->setDescription(new Description('Helpful description'))
->setDeprecationTag(new DeprecationTag())
;

$this->needsLineAfter($methodPhpdoc, 'description')->shouldBe(true);
}

function it_needs_line_after_parameter_tags_if_it_has_api_or_deprecation_tags(
DeprecationTag $deprecationTag,
MethodPhpdoc $methodPhpdoc,
ParameterTag $parameterTag
) {
$methodPhpdoc->getApiTag()->willReturn(null);
$methodPhpdoc->getDescription()->willReturn(null);
$methodPhpdoc->getDeprecationTag()->willReturn($deprecationTag);
$methodPhpdoc->getParameterTags()->willReturn([$parameterTag]);
$methodPhpdoc->getReturnTag()->willReturn(null);
$methodPhpdoc->getThrowTags()->willReturn([]);
function it_needs_a_new_line_after_parameter_tags_if_it_has_a_deprecation_tag()
{
$methodPhpdoc = (new MethodPhpdoc())
->addParameterTag(new ParameterTag('string', 'filename'))
->setDeprecationTag(new DeprecationTag())
;

$this->needsLineAfter($methodPhpdoc, 'parameter_tags')->shouldBe(true);
}

function it_needs_line_after_deprecation_it_also_has_an_api_tag(
ApiTag $apiTag,
DeprecationTag $deprecationTag,
MethodPhpdoc $methodPhpdoc
) {
$methodPhpdoc->getDeprecationTag()->willReturn($deprecationTag);
$methodPhpdoc->getDescription()->willReturn(null);
$methodPhpdoc->getApiTag()->willReturn($apiTag);
$methodPhpdoc->getParameterTags()->willReturn([]);
$methodPhpdoc->getReturnTag()->willReturn(null);
$methodPhpdoc->getThrowTags()->willReturn([]);
function it_needs_a_new_line_after_deprecation_if_it_also_has_an_api_tag()
{
$methodPhpdoc = (new MethodPhpdoc())
->setDeprecationTag(new DeprecationTag())
->setApiTag(new ApiTag())
;

$this->needsLineAfter($methodPhpdoc, 'deprecation_tag')->shouldBe(true);
}
Expand Down
Loading

0 comments on commit 34d0c08

Please sign in to comment.