Skip to content

Commit

Permalink
Merge pull request #16 from vossik/sql_generators
Browse files Browse the repository at this point in the history
sql generator command
  • Loading branch information
peldax authored Dec 11, 2020
2 parents 3d743fa + 77b67df commit 3144005
Show file tree
Hide file tree
Showing 54 changed files with 795 additions and 271 deletions.
72 changes: 69 additions & 3 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
branches: [ master ]

jobs:
build:
tests:
runs-on: ubuntu-latest

steps:
Expand All @@ -30,5 +30,71 @@ jobs:
- name: Tests
run: composer run-script phpunit

- name: Mutation tests
run: composer run-script infection
mutation:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
coverage: xdebug
env:
update: true

- name: Validate composer.json and composer.lock
run: composer validate

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: Mutation tests
run: composer run-script infection

phpstan:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
coverage: xdebug
env:
update: true

- name: Validate composer.json and composer.lock
run: composer validate

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: PHPStan
run: composer run-script phpstan

codestyle:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
coverage: xdebug
env:
update: true

- name: Validate composer.json and composer.lock
run: composer validate

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: Codestyle
run: composer run-script codestyle
15 changes: 12 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,25 @@
"php": ">=8.0",
"infinityloop-dev/utils": "^2.1",
"nette/utils": "^3.0",
"nette/database": "^3.0"
"nette/database": "^3.0",
"nette/robot-loader": "^3.3",
"symfony/console": "^5.2"
},
"scripts": {
"phpunit": "phpunit tests",
"infection": "infection"
"infection": "infection",
"phpstan": "phpstan analyze --level 1 src",
"phpstan-next": "phpstan analyze --level 2 src",
"phpstan-max": "phpstan analyze --level max src",
"codestyle": "phpcs --standard=vendor/infinityloop-dev/coding-standard/InfinityloopCodingStandard/ruleset.xml --extensions=php src tests",
"codestyle-fix": "phpcbf --standard=vendor/infinityloop-dev/coding-standard/InfinityloopCodingStandard/ruleset.xml --extensions=php src tests"
},
"require-dev": {
"phpunit/phpunit": "^9.3",
"mockery/mockery": "^1.4",
"infection/infection": "^0.20"
"infection/infection": "^0.20",
"phpstan/phpstan": "^0.12",
"infinityloop-dev/coding-standard": "^0.1"
},
"autoload": {
"psr-4": {
Expand Down
13 changes: 13 additions & 0 deletions src/Attribute/DefaultValue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types = 1);

namespace CoolBeans\Attribute;

#[\Attribute(\Attribute::TARGET_PROPERTY)]
final class DefaultValue
{
public function __construct(
public string $defaultValue
) {}
}
13 changes: 13 additions & 0 deletions src/Attribute/Defaults/MysqlDefaults.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types = 1);

namespace CoolBeans\Attribute\Defaults;

final class MysqlDefaults
{
use \Nette\StaticClass;

public const CURRENT_TIMESTAMP = 'CURRENT_TIMETAMP()';
public const NOW = 'NOW()';
}
28 changes: 28 additions & 0 deletions src/Attribute/TypeOverride.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types = 1);

namespace CoolBeans\Attribute;

#[\Attribute(\Attribute::TARGET_PROPERTY)]
final class TypeOverride
{
public array $lengthArgs;

public function __construct(
public string $type,
int ...$lengthArgs
)
{
$this->lengthArgs = $lengthArgs;
}

public function getType() : string
{
if (\count($this->lengthArgs) === 0) {
return $this->type;
}

return $this->type . '(' . \implode(',', $this->lengthArgs) . ')';
}
}
39 changes: 39 additions & 0 deletions src/Attribute/Types/MysqlTypes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types = 1);

namespace CoolBeans\Attribute\Types;

final class MysqlTypes
{
use \Nette\StaticClass;

public const TIMESTAMP = 'TIMESTAMP';
public const DATETIME = 'DATETIME';
public const DATE = 'DATE';
public const TIME = 'TIME';
public const YEAR = 'YEAR';
public const BIT = 'BIT';
public const INT = 'INT';
public const TINYINT = 'TINYINT';
public const SMALLINT = 'SMALLINT';
public const MEDIUMINT = 'MEDIUMINT';
public const BIGINT = 'BIGINT';
public const FLOAT = 'FLOAT';
public const DOUBLE = 'DOUBLE';
public const DECIMAL = 'DECIMAL';
public const CHAR = 'CHAR';
public const VARCHAR = 'VARCHAR';
public const BINARY = 'BINARY';
public const VARBINARY = 'VARBINARY';
public const TINYBLOB = 'TINYBLOB';
public const TINYTEXT = 'TINYTEXT';
public const TEXT = 'TEXT';
public const BLOB = 'BLOB';
public const MEDIUMTEXT = 'MEDIUMTEXT';
public const MEDIUMBLOB = 'MEDIUMBLOB';
public const LONGTEXT = 'LONGTEXT';
public const LONGBLOB = 'LONGBLOB';
public const BOOL = 'BOOL';
public const JSON = 'JSON';
}
10 changes: 5 additions & 5 deletions src/Bean.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace CoolBeans;

use CoolBeans\Contract\PrimaryKey;
use \CoolBeans\Contract\PrimaryKey;

abstract class Bean implements \CoolBeans\Contract\Row, \IteratorAggregate
{
Expand All @@ -24,7 +24,7 @@ final public function __construct(\Nette\Database\Table\ActiveRow $row)
$this->validateMissingColumns();
}

if (\CoolBeans\Config::$validateTableName){
if (\CoolBeans\Config::$validateTableName) {
$this->validateTableName();
}

Expand Down Expand Up @@ -66,7 +66,7 @@ public function getIterator() : \Traversable
/**
* Array access interface method.
*/
public function offsetGet($offset)
public function offsetGet($offset) : mixed
{
if ($this->offsetExists($offset)) {
return $this->{$offset};
Expand Down Expand Up @@ -164,10 +164,10 @@ protected function initiateProperties() : void
$type = $property->getType();
$value = $this->row[$name];

if (!$type instanceof \ReflectionType) {
if (!$type instanceof \ReflectionNamedType) {
throw new \CoolBeans\Exception\MissingType('Property [' . $property->getName() . '] does not have type.');
}

if ($value === null) {
if ($type->allowsNull()) {
$this->{$name} = null;
Expand Down
4 changes: 2 additions & 2 deletions src/Bridge/Nette/ActiveRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ class ActiveRow extends \Nette\Database\Table\ActiveRow implements \CoolBeans\Co
{
protected ?\CoolBeans\Contract\PrimaryKey $primaryKey = null;

public function getTableName(): string
public function getTableName() : string
{
return $this->getTable()->getName();
}

public function getPrimaryKey(): \CoolBeans\Contract\PrimaryKey
public function getPrimaryKey() : \CoolBeans\Contract\PrimaryKey
{
if (!$this->primaryKey instanceof \CoolBeans\Contract\PrimaryKey) {
$this->primaryKey = \CoolBeans\Contract\PrimaryKey::create($this);
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Nette/DataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace CoolBeans\Bridge\Nette;

use CoolBeans\Contract\PrimaryKey;
use \CoolBeans\Contract\PrimaryKey;

interface DataSource extends \CoolBeans\Contract\DataSource
{
Expand Down
8 changes: 3 additions & 5 deletions src/Bridge/Nette/Selection.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ public function getTableName() : string

public function current() : ?\CoolBeans\Bridge\Nette\ActiveRow
{
if (($key = current($this->keys)) !== false) {
return $this->data[$key];
} else {
return null;
}
return ($key = \current($this->keys)) !== false
? $this->data[$key]
: null;
}

protected function createRow(array $row) : \CoolBeans\Bridge\Nette\ActiveRow
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Nette/TDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace CoolBeans\Bridge\Nette;

use CoolBeans\Contract\PrimaryKey;
use \CoolBeans\Contract\PrimaryKey;

trait TDecorator
{
Expand Down
Loading

0 comments on commit 3144005

Please sign in to comment.