Skip to content

Commit db27047

Browse files
authored
Merge pull request #90 from dunglas/mutators
Add an option to not generate mutator methods
2 parents c6469d2 + d22d318 commit db27047

14 files changed

+58
-8
lines changed

.php_cs.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ HEADER;
1212
$finder = PhpCsFixer\Finder::create()
1313
->in(__DIR__)
1414
->exclude('tests/Fixtures/app/cache')
15+
->exclude('build')
1516
;
1617

1718
return PhpCsFixer\Config::create()

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ install:
3030
- if [[ $deps = 'low' ]]; then composer update --prefer-dist --no-progress --no-suggest --prefer-stable --prefer-lowest --ansi; fi
3131

3232
script:
33-
- if [[ $coverage = 1 ]]; then phpdbg -qrr php phpunit-6.3.phar --coverage-closer build/logs/clover.xml; else php phpunit-6.3.phar; fi
33+
- if [[ $coverage = 1 ]]; then phpdbg -qrr phpunit-6.3.phar --coverage-clover build/logs/clover.xml; else php phpunit-6.3.phar; fi
3434
- if [[ $lint = 1 ]]; then php php-cs-fixer.phar fix --dry-run --diff --no-ansi; fi
3535
- if [[ $lint = 1 ]]; then phpstan analyse -l5 --ansi src; fi
3636
- if [[ ! $deps && $TRAVIS_PHP_VERSION = "7.1" ]]; then php box.phar build; fi;

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* A fluent interface isn't generated anymore
88
* Useless PHPDoc (`@param` and `@return` annotations when a typehint exist and mutator description) isn't generated anymore
99
* `DateTimeInterface` is used instead of `DateTime` when possible
10+
* Add the ability to not generate mutator methods (useful when generating public properties)
1011
* The `extract-cardinalities` gains two new options: one to configure the Schema.org's file to use, the other for the GoodRelations one
1112
* The annotation generator for API Platform v1 has been dropped. Only API Platform v2 is now supported.
1213
* Parent class is not generated by default anymore (using inheritance for entity is discouraged)

src/TypesGeneratorConfiguration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ function ($rdfa) {
9393
->end()
9494
->scalarNode('author')->defaultFalse()->info('The value of the phpDoc\'s @author annotation')->example('Kévin Dunglas <[email protected]>')->end()
9595
->enumNode('fieldVisibility')->values(['private', 'protected', 'public'])->defaultValue('private')->cannotBeEmpty()->info('Visibility of entities fields')->end()
96+
->booleanNode('mutatorMethods')->defaultTrue()->info('Set this flag to false to not generate getter, setter, adder and remover methods')->end()
9697
->arrayNode('types')
9798
->beforeNormalization()
9899
->always()

templates/class.php.twig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ use {{ use }};
5959
}
6060
{% endif %}
6161
62+
{% if config.mutatorMethods %}
6263
{% for field in class.fields %}
6364
{% if field.isArray %}
6465
/**
@@ -110,4 +111,5 @@ use {{ use }};
110111
}
111112
112113
{% endfor %}
114+
{% endif %}
113115
}

tests/Command/DumpConfigurationTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ interface: AppBundle\Model # Example: Acme\Model
8989
# Visibility of entities fields
9090
fieldVisibility: private # One of "private"; "protected"; "public"
9191
92+
# Set this flag to false to not generate getter, setter, adder and remover methods
93+
mutatorMethods: true
94+
9295
# Schema.org's types to use
9396
types:
9497

tests/Command/GenerateTypesCommandTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class GenerateTypesCommandTest extends TestCase
3131
public function setUp()
3232
{
3333
$this->fs = new Filesystem();
34-
$this->fs->remove(__DIR__.'/../../build/');
3534
}
3635

3736
/**
@@ -48,12 +47,13 @@ public function testCommand($output, $config)
4847
public function getArguments()
4948
{
5049
return [
51-
[__DIR__.'/../../build/address-book/', __DIR__.'/../config/address-book.yml'],
52-
[__DIR__.'/../../build/blog/', __DIR__.'/../config/blog.yml'],
53-
[__DIR__.'/../../build/ecommerce/', __DIR__.'/../config/ecommerce.yml'],
54-
[__DIR__.'/../../build/vgo/', __DIR__.'/../config/vgo.yml'],
55-
[__DIR__.'/../../build/mongodb/address-book/', __DIR__.'/../config/mongodb/address-book.yml'],
56-
[__DIR__.'/../../build/mongodb/ecommerce/', __DIR__.'/../config/mongodb/ecommerce.yml'],
50+
[__DIR__.'/../../build/address-book/', __DIR__.'/../config/address-book.yaml'],
51+
[__DIR__.'/../../build/blog/', __DIR__.'/../config/blog.yaml'],
52+
[__DIR__.'/../../build/ecommerce/', __DIR__.'/../config/ecommerce.yaml'],
53+
[__DIR__.'/../../build/vgo/', __DIR__.'/../config/vgo.yaml'],
54+
[__DIR__.'/../../build/public-properties/', __DIR__.'/../config/public-properties.yaml'],
55+
[__DIR__.'/../../build/mongodb/address-book/', __DIR__.'/../config/mongodb/address-book.yaml'],
56+
[__DIR__.'/../../build/mongodb/ecommerce/', __DIR__.'/../config/mongodb/ecommerce.yaml'],
5757
];
5858
}
5959
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)