Skip to content

Commit

Permalink
refactoring, add qa and phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
dakorpar committed Feb 23, 2019
1 parent 02efa93 commit 64ec4fe
Show file tree
Hide file tree
Showing 17 changed files with 308 additions and 193 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/.idea
/vendor
/temp
/composer.lock
.phpunit.result.cache
27 changes: 27 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,37 @@
"php": "^7.1",
"nette/utils": "^2.4|^3.0",
"nette/php-generator": "^2.6|^3.0",
"ninjify/qa": "^0.8",
"symfony/console": "^4.2",
"doctrine/inflector": "^1.3"
},
"require-dev": {
"phpunit/phpunit": "^8.0"
},
"scripts": {
"qa": [
"codesniffer src tests",
"linter src tests"
],
"codefixer": [
"codefixer"
],
"tests": [
"phpunit --configuration tests/unit/phpunit.xml tests/unit/Tests"
],
"coverage": [
"phpunit --configuration testsphpunit.xml tests --coverage-clover=coverage.xml"
],
"phpstan-install": [
"mkdir -p temp/phpstan",
"composer require -d temp/phpstan phpstan/phpstan:^0.11",
"composer require -d temp/phpstan phpstan/phpstan-dibi:^0.11",
"composer require -d temp/phpstan phpstan/phpstan-deprecation-rules:^0.11",
"composer require -d temp/phpstan phpstan/phpstan-nette:^0.11",
"composer require -d temp/phpstan phpstan/phpstan-strict-rules:^0.11"
],
"phpstan": [
"temp/phpstan/vendor/bin/phpstan analyse -l 1 -c phpstan.neon src --memory-limit 1024M"
]
}
}
9 changes: 9 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
includes:
- temp/phpstan/vendor/phpstan/phpstan-deprecation-rules/rules.neon
- temp/phpstan/vendor/phpstan/phpstan-nette/extension.neon
- temp/phpstan/vendor/phpstan/phpstan-nette/rules.neon
- temp/phpstan/vendor/phpstan/phpstan-strict-rules/rules.neon

parameters:
ignoreErrors:
- '#Variable property access on \$[a-zA-Z0-9_]+#'
49 changes: 49 additions & 0 deletions ruleset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="Heimkaup ruleset">
<rule ref="./vendor/ninjify/coding-standard/ruleset.xml">
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration"/>
<exclude name="SlevomatCodingStandard.Commenting.RequireOneLinePropertyDocComment" />
<exclude name="SlevomatCodingStandard.Operators.DisallowIncrementAndDecrementOperators" />
</rule>
<rule name="SlevomatCodingStandard.Commenting.DisallowOneLinePropertyDocComment" />
<rule ref="Generic.WhiteSpace.ScopeIndent">
<properties>
<property name="indent" value="4"/>
<property name="tabIndent" value="true"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
<properties>
<property name="allowFullyQualifiedGlobalClasses" value="true"/>
<property name="tabIndent" value="true"/>
</properties>
</rule>
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/>
<rule ref="Generic.Metrics.CyclomaticComplexity">
<properties>
<property name="complexity" value="14" />
<property name="absoluteComplexity" value="14" />
</properties>
</rule>
<rule ref="Generic.Metrics.NestingLevel">
<properties>
<property name="nestingLevel" value="3"/>
<property name="absoluteNestingLevel" value="4"/>
</properties>
</rule>

<!-- tests are named differently -->
<rule ref="Generic.NamingConventions.CamelCapsFunctionName.ScopeNotCamelCaps">
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>
<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>
<rule ref="Squiz.Classes.ClassFileName.NoMatch">
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>
<rule ref="Generic.Files.LineLength"></rule>
</ruleset>
85 changes: 0 additions & 85 deletions src/Entity.php

This file was deleted.

35 changes: 10 additions & 25 deletions src/Generator/Column.php → src/Entity/Column.php
Original file line number Diff line number Diff line change
@@ -1,44 +1,28 @@
<?php declare (strict_types=1);

namespace DodoIt\EntityGenerator\Generator;

use DodoIt\EntityGenerator\Entity;
<?php declare (strict_types = 1);

namespace DodoIt\EntityGenerator\Entity;

class Column extends Entity
{

/**
* @var string
*/
/** @var string */
protected $Field;

/**
* @var string
*/
/** @var string */
protected $Type;

/**
* @var string
*/
/** @var string */
protected $Null;

/**
* @var string
*/
/** @var string */
protected $Key;

/**
* @var string
*/
/** @var string */
protected $Default;

/**
* @var $Extra
*/
/** @var string */
protected $Extra;


public function getField(): string
{
return $this->Field;
Expand Down Expand Up @@ -73,4 +57,5 @@ public function getExtra(): ?string
{
return $this->Extra;
}
}

}
106 changes: 106 additions & 0 deletions src/Entity/Entity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php declare (strict_types = 1);

namespace DodoIt\EntityGenerator\Entity;

use ArrayAccess;
use ArrayIterator;
use Countable;
use Exception;
use IteratorAggregate;

class Entity implements ArrayAccess, IteratorAggregate, Countable
{

public const TABLE = null;

/** @var mixed[] */
protected $data;

/** @var mixed[] */
private $modifications = [];

public function __construct(array $arr = [])
{
$this->data = $arr;
foreach ($arr as $k => $v) {
$this->$k = $v;
}
}


public function _getModifications(): array
{
return $this->modifications;
}


public function tableName(): ?string
{
return static::TABLE;
}

/**
* @return int
*/
public function count()
{
return count($this->data);
}


public function toArray(): array
{
return $this->data;
}

/**
* @return ArrayIterator
*/
public function getIterator()
{
return new ArrayIterator($this->data);
}

/**
* @param string $nm
* @param mixed $val
* @return void
*/
public function offsetSet($nm, $val)
{
$this->data[$nm] = $val;
$this->modifications[$nm] = $val;
$this->$nm = $val;
}


/**
* @param string $nm
* @return void
*/
public function offsetGet($nm)
{
throw new Exception('You should never access entity as array');
}


/**
* @param string $nm
* @return void
*/
public function offsetExists($nm)
{
throw new Exception('You should never access entity as array');
}


/**
* @param string $nm
* @return void
*/
public function offsetUnset($nm)
{
throw new Exception('You should never access entity as array');
}

}
Loading

0 comments on commit 64ec4fe

Please sign in to comment.