Skip to content

Commit a02744a

Browse files
committed
Coding standard
1 parent 660d645 commit a02744a

14 files changed

Lines changed: 310 additions & 60 deletions

File tree

.editorconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
3+
root = true
4+
5+
[*]
6+
charset = utf-8
7+
end_of_line = lf
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
indent_style = tab
11+
indent_size = tab
12+
tab_width = 4
13+
14+
[{*.json,*.yml,*.md}]
15+
indent_style = space
16+
indent_size = 2

.gitattributes

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Not archived
2+
.docs export-ignore
3+
tests export-ignore
4+
.editorconfig export-ignore
5+
.gitattributes export-ignore
6+
.gitignore export-ignore
7+
.travis.yml export-ignore
8+
phpstan.neon export-ignore
9+
README.md export-ignore
10+
ruleset.xml export-ignore

.gitignore

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1-
.idea
2-
composer.lock
1+
# IDE
2+
/.idea
3+
4+
# Composer
35
/vendor
6+
/composer.lock
7+
8+
# Tests
9+
/temp
10+
/coverage.xml

.travis.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
language: php
2+
php:
3+
- 7.1
4+
- 7.2
5+
- 7.3
6+
7+
before_install:
8+
# Turn off XDebug
9+
- phpenv config-rm xdebug.ini || return 0
10+
11+
install:
12+
# Composer
13+
- travis_retry composer install --no-progress --prefer-dist
14+
15+
script:
16+
# Tests
17+
- composer run-script tests
18+
19+
after_failure:
20+
# Print *.actual content
21+
- for i in $(find tests -name \*.actual); do echo "--- $i"; cat $i; echo; echo; done
22+
23+
jobs:
24+
include:
25+
- env: title="Lowest Dependencies 7.1"
26+
php: 7.1
27+
install:
28+
- travis_retry composer update --no-progress --prefer-dist --prefer-lowest
29+
script:
30+
- composer run-script tests
31+
32+
- stage: Quality Assurance
33+
php: 7.1
34+
script:
35+
- composer run-script qa
36+
37+
- stage: Phpstan
38+
php: 7.1
39+
script:
40+
- composer run-script phpstan-install
41+
- composer run-script phpstan
42+
43+
- stage: Test Coverage
44+
if: branch = master AND type = push
45+
php: 7.1
46+
script:
47+
- composer run-script coverage
48+
after_script:
49+
- wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.1.0/php-coveralls.phar
50+
- php php-coveralls.phar --verbose --config tests/.coveralls.yml
51+
52+
- stage: Outdated Dependencies
53+
if: branch = master AND type = cron
54+
php: 7.1
55+
script:
56+
- composer outdated --direct --strict
57+
58+
allow_failures:
59+
- stage: Test Coverage
60+
61+
sudo: false
62+
63+
cache:
64+
directories:
65+
- $HOME/.composer/cache

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ extensions:
1616
1717
```yaml
1818
ormGenerator:
19-
directory: '%appDir%/model/orm'
20-
namespace: 'App\Model'
21-
entityExtends: 'App\Model\BaseEntity'
22-
repositoryExtends: 'App\Model\BaseRepository'
23-
mapperExtends: 'App\Model\BaseMapper'
19+
directory: '%appDir%/Model/Orm'
20+
namespace: 'App\Model\Orm'
21+
entityExtends: 'App\Model\Orm\BaseEntity'
22+
repositoryExtends: 'App\Model\Orm\BaseRepository'
23+
mapperExtends: 'App\Model\Orm\BaseMapper'
2424
```
2525
2626
## Usage
@@ -35,7 +35,7 @@ This command creates entity, repository and mapper in ```%directory%/Product```.
3535

3636
```php
3737
<?php
38-
namespace App\Model;
38+
namespace App\Model\Orm\Product;
3939

4040
/**
4141
* @property int $id {primary}
@@ -49,7 +49,7 @@ class Product extends BaseEntity
4949

5050
```php
5151
<?php
52-
namespace App\Model;
52+
namespace App\Model\Orm\Product;
5353

5454
class ProductsRepository extends BaseRepository
5555
{
@@ -64,7 +64,7 @@ class ProductsRepository extends BaseRepository
6464

6565
```php
6666
<?php
67-
namespace App\Model;
67+
namespace App\Model\Orm\Product;
6868

6969
class ProductsMapper extends BaseMapper
7070
{

composer.json

Lines changed: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,58 @@
11
{
2-
"name": "martenb/nextras-orm-code-generator",
3-
"description": "Console entity, repository and mapper generator for Nextras/ORM",
4-
"keywords": ["generator", "nextras", "orm", "nette"],
5-
"type": "library",
6-
"license": "MIT",
7-
"authors": [
8-
{
9-
"name": "Martin Brettschneider"
10-
}
11-
],
12-
"autoload": {
13-
"psr-4": {
14-
"MartenB\\Nextras\\ORM\\": "src/"
15-
}
16-
},
17-
"require": {
18-
"php": ">=7.1",
19-
"nette/php-generator": "^2.4 || ^3.0",
20-
"nextras/orm": "^3.0",
21-
"symfony/console": "~3.3 || ^4.0"
22-
},
23-
"require-dev": {
24-
"nette/di": "^2.4"
25-
}
2+
"name": "martenb/nextras-orm-code-generator",
3+
"description": "Console entity, repository and mapper generator for Nextras/ORM",
4+
"keywords": [
5+
"generator",
6+
"nextras",
7+
"orm",
8+
"nette"
9+
],
10+
"type": "library",
11+
"license": "MIT",
12+
"authors": [
13+
{
14+
"name": "Martin Brettschneider"
15+
}
16+
],
17+
"autoload": {
18+
"psr-4": {
19+
"MartenB\\Nextras\\ORM\\": "src/"
20+
}
21+
},
22+
"require": {
23+
"php": ">=7.1",
24+
"nette/php-generator": "^2.4 || ^3.0",
25+
"nextras/orm": "^3.0",
26+
"symfony/console": "~3.3 || ^4.0"
27+
},
28+
"require-dev": {
29+
"ninjify/qa": "^0.9",
30+
"nette/di": "^2.4.1 || ^3.0",
31+
"ninjify/nunjuck": "^0.2.1"
32+
},
33+
"scripts": {
34+
"qa": [
35+
"parallel-lint -e php,phpt --blame src tests",
36+
"phpcs --standard=vendor/ninjify/coding-standard/ruleset.xml --ignore=*/temp,*/tmp --extensions=php,phpt --encoding=utf-8 --colors -nsp src tests"
37+
],
38+
"qa-fix": [
39+
"phpcbf --standard=vendor/ninjify/coding-standard/ruleset.xml --ignore=*/temp,*/tmp --extensions=php,phpt --encoding=utf-8 --colors -nsp src tests"
40+
],
41+
"tests": [
42+
"tester -s -p php --colors 1 -C tests/cases"
43+
],
44+
"coverage": [
45+
"tester -s -p phpdbg --colors 1 -C --coverage ./coverage.xml --coverage-src ./src tests/cases"
46+
],
47+
"phpstan-install": [
48+
"mkdir -p temp/phpstan",
49+
"composer require -d temp/phpstan phpstan/phpstan:^0.11",
50+
"composer require -d temp/phpstan phpstan/phpstan-deprecation-rules:^0.11",
51+
"composer require -d temp/phpstan phpstan/phpstan-nette:^0.11",
52+
"composer require -d temp/phpstan phpstan/phpstan-strict-rules:^0.11"
53+
],
54+
"phpstan": [
55+
"temp/phpstan/vendor/bin/phpstan analyse -l max -c phpstan.neon src tests"
56+
]
57+
}
2658
}

phpstan.neon

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
parameters:
2+
excludes_analyse:
3+
- */tmp/*
4+
ignoreErrors:
5+
-
6+
message: '#^Call to deprecated method validateConfig\(\) of class Nette\\DI\\CompilerExtension#'
7+
path: %currentWorkingDirectory%/src/DI/Extension.php
8+
-
9+
message: '#^Constant TEMP_DIR not found\.$#'
10+
path: %currentWorkingDirectory%/tests/bootstrap.php
11+
includes:
12+
- temp/phpstan/vendor/phpstan/phpstan-deprecation-rules/rules.neon
13+
- temp/phpstan/vendor/phpstan/phpstan-nette/extension.neon
14+
- temp/phpstan/vendor/phpstan/phpstan-nette/rules.neon
15+
- temp/phpstan/vendor/phpstan/phpstan-strict-rules/rules.neon
Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types = 1);
22

33
namespace MartenB\Nextras\ORM\Console\Command;
44

@@ -13,16 +13,16 @@
1313
class GeneratorCommand extends Command
1414
{
1515

16+
/** @var mixed[] */
1617
private $config = [
17-
'directory' => NULL,
18-
'namespace' => 'App\Model',
19-
'entityExtends' => 'App\Model\BaseEntity',
20-
'repositoryExtends' => 'App\Model\BaseRepository',
21-
'mapperExtends' => 'App\Model\BaseMapper',
18+
'directory' => null,
19+
'namespace' => 'App\Model\Orm',
20+
'entityExtends' => 'App\Model\Orm\BaseEntity',
21+
'repositoryExtends' => 'App\Model\Orm\BaseRepository',
22+
'mapperExtends' => 'App\Model\Orm\BaseMapper',
2223
];
2324

24-
25-
protected function configure()
25+
protected function configure(): void
2626
{
2727
$this->setName('orm:generator')
2828
->setDescription('Generate entity, repository and mapper')
@@ -36,32 +36,46 @@ protected function configure()
3636
->addOption('mapperExtends', 'me', InputOption::VALUE_OPTIONAL, 'Mapper extends class name');
3737
}
3838

39-
40-
public function setConfig(array $config = [])
39+
/**
40+
* @param string[] $config
41+
*/
42+
public function setConfig(array $config = []): void
4143
{
4244
$this->config = $config;
4345
}
4446

45-
46-
protected function getOption(InputInterface $input, string $name)
47+
protected function getOption(InputInterface $input, string $name): string
4748
{
4849
return $input->getOption($name) ?? $this->config[$name];
4950
}
5051

51-
52-
protected function execute(InputInterface $input, OutputInterface $output)
52+
protected function execute(InputInterface $input, OutputInterface $output): ?int
5353
{
54+
if (!is_string($input->getArgument('entityName'))) {
55+
throw new Exception('Argument entityName must be a string.');
56+
}
57+
58+
if (is_array($input->getArgument('repositoryName'))) {
59+
throw new Exception('Argument entityName must be a string or null.');
60+
}
61+
62+
if (is_array($input->getArgument('mapperName'))) {
63+
throw new Exception('Argument entityName must be a string or null.');
64+
}
65+
5466
$directory = $this->getOption($input, 'directory') . '/' . $input->getArgument('entityName');
67+
5568
if (is_dir($directory)) {
5669
throw new Exception('Directory already exists.');
5770
}
58-
mkdir($directory, 0777, TRUE);
71+
72+
mkdir($directory, 0777, true);
5973

6074
$namespace = $this->getOption($input, 'namespace') . '\\' . $input->getArgument('entityName');
6175

6276
// entity
6377
$entityName = $input->getArgument('entityName');
64-
$file = new PhpFile;
78+
$file = new PhpFile();
6579
$file
6680
->addNamespace($namespace)
6781
->addClass($entityName)
@@ -72,27 +86,29 @@ protected function execute(InputInterface $input, OutputInterface $output)
7286

7387
// repository
7488
$repositoryName = ($input->getArgument('repositoryName') ?? $input->getArgument('entityName')) . 'Repository';
75-
$file = new PhpFile;
89+
$file = new PhpFile();
7690
$file
7791
->addNamespace($namespace)
7892
->addClass($repositoryName)
7993
->setExtends($this->getOption($input, 'repositoryExtends'))
8094
->addMethod('getEntityClassNames')
81-
->setStatic(TRUE)
95+
->setStatic(true)
8296
->setReturnType('array')
8397
->setBody('return [' . $input->getArgument('entityName') . '::class];');
8498

8599
file_put_contents($directory . '/' . $repositoryName . '.php', (string) $file);
86100

87101
// mapper
88102
$mapperName = ($input->getArgument('mapperName') ?? ($input->getArgument('repositoryName') ?? $input->getArgument('entityName'))) . 'Mapper';
89-
$file = new PhpFile;
103+
$file = new PhpFile();
90104
$file
91105
->addNamespace($namespace)
92106
->addClass($mapperName)
93107
->setExtends($this->getOption($input, 'mapperExtends'));
94108

95109
file_put_contents($directory . '/' . $mapperName . '.php', (string) $file);
110+
111+
return 0;
96112
}
97113

98114
}

0 commit comments

Comments
 (0)