Skip to content

Commit

Permalink
Merge pull request #7 from UseMuffin/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
ADmad authored Jan 16, 2020
2 parents 91c862a + 370cbe5 commit 529841c
Show file tree
Hide file tree
Showing 23 changed files with 253 additions and 131 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.semver export-ignore
phpunit.xml.dist export-ignore
.travis.yml export-ignore
tests export-ignore
phpstan.neon
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/composer.lock
/plugins
/vendor
/tmp
/phpcs.xml
/phpunit.xml
6 changes: 0 additions & 6 deletions .semver

This file was deleted.

46 changes: 27 additions & 19 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7
- 7.2
- 7.4

sudo: false
services:
- mysql
- postgresql

env:
matrix:
- DB=mysql db_dsn='mysql://travis@0.0.0.0/cakephp_test'
- DB=mysql db_dsn='mysql://root@127.0.0.1/cakephp_test'
- DB=pgsql db_dsn='postgres://[email protected]/cakephp_test'
- DB=sqlite db_dsn='sqlite:///:memory:'

Expand All @@ -21,29 +22,36 @@ matrix:
fast_finish: true

include:
- php: 5.4
- php: 7.1
env: PHPCS=1 DEFAULT=0

- php: 5.4
env: COVERALLS=1 DEFAULT=0 DB=mysql db_dsn='mysql://[email protected]/cakephp_test'
- php: 7.1
env: PHPSTAN=1 DEFAULT=0

- php: 5.6
env: PREFER_LOWEST=1

before_script:
- composer self-update
- composer install --prefer-dist --no-interaction
- if [[ $TRAVIS_PHP_VERSION != 7.4 ]]; then phpenv config-rm xdebug.ini; fi

- sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'CREATE DATABASE cakephp_test;'; fi"
- sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi"
- if [[ $DB == 'mysql' ]]; then mysql -e 'CREATE DATABASE cakephp_test;'; fi
- if [[ $DB == 'pgsql' ]]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi

- sh -c "if [ '$PHPCS' = '1' ]; then composer require cakephp/cakephp-codesniffer:dev-master; fi"
- if [[ $PREFER_LOWEST != 1 ]]; then composer update --no-interaction; fi
- if [[ $PREFER_LOWEST == 1 ]]; then composer update --no-interaction --prefer-lowest --prefer-stable; fi

- sh -c "if [ '$COVERALLS' = '1' ]; then composer require --dev satooshi/php-coveralls:dev-master; fi"
- sh -c "if [ '$COVERALLS' = '1' ]; then mkdir -p build/logs; fi"
- if [[ $PHPCS == 1 ]]; then composer require cakephp/cakephp-codesniffer:"^3.0"; fi

script:
- sh -c "if [ '$DEFAULT' = '1' ]; then phpunit --stderr; fi"
- sh -c "if [ '$PHPCS' = '1' ]; then ./vendor/bin/phpcs -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi"
- sh -c "if [ '$COVERALLS' = '1' ]; then phpunit --stderr --coverage-clover build/logs/clover.xml; fi"
- sh -c "if [ '$COVERALLS' = '1' ]; then php vendor/bin/coveralls -c .coveralls.yml -v; fi"
- if [[ $DEFAULT == 1 && $TRAVIS_PHP_VERSION != 7.4 ]]; then vendor/bin/phpunit; fi
- if [[ $DEFAULT == 1 && $TRAVIS_PHP_VERSION == 7.4 ]]; then vendor/bin/phpunit --coverage-clover=clover.xml; fi

- if [[ $PHPCS == 1 ]]; then vendor/bin/phpcs -n -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi

- if [[ $PHPSTAN == 1 ]]; then composer require --dev phpstan/phpstan:^0.12 && vendor/bin/phpstan analyse src; fi

after_success:
- if [[ $DEFAULT == 1 && $TRAVIS_PHP_VERSION == 7.4 ]]; then bash <(curl -s https://codecov.io/bash); fi

notifications:
email: false
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2015 Use Muffin
Copyright (c) 2015-Present Use Muffin

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
40 changes: 17 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
[![Total Downloads](https://img.shields.io/packagist/dt/muffin/sti.svg?style=flat-square)](https://packagist.org/packages/muffin/sti)
[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE)

Single Table Inheritance for CakePHP 3 ORM.
Single Table Inheritance for CakePHP ORM.

> [...] a way to emulate object-oriented inheritance in a relational database. When mapping from a database
> table to an object in an object-oriented language, a field in the database identifies what class in the
> [...] a way to emulate object-oriented inheritance in a relational database. When mapping from a database
> table to an object in an object-oriented language, a field in the database identifies what class in the
> hierarchy the object belongs to.
(source: [Wikipedia][1])
Expand All @@ -18,21 +18,15 @@ Single Table Inheritance for CakePHP 3 ORM.
Using [Composer][composer]:

```
composer require muffin/sti:1.0.x-dev
composer require muffin/sti
```

You then need to load the plugin. You can use the shell command:
You then need to load the plugin. You can use the console command:

```
bin/cake plugin load Muffin/Sti
```

or by manually adding statement shown below to `bootstrap.php`:

```php
Plugin::load('Muffin/Sti');
```

## Usage

```php
Expand All @@ -41,8 +35,8 @@ namespace App\Model\Table;

use Cake\ORM\Table;

class CooksTable extends Table {

class CooksTable extends Table
{
public function initialize($config)
{
$this->table('sti_cooks');
Expand All @@ -56,7 +50,7 @@ class CooksTable extends Table {

// Optionally, set the default type. If none is defined, the
// first one (i.e. `chef`) will be used.
$this->entityClass('App\Model\Entity\AssistantChef');
$this->setEntityClass('App\Model\Entity\AssistantChef');
}
}
```
Expand All @@ -69,7 +63,7 @@ Then create a class for every type of entity:

The entity that was previously defined to be the 'default' one will need to use the `StiAwareTrait`:

```
```php
<?php // src/Model/Entity/AssistantChef.php
namespace App\Model\Entity;

Expand All @@ -88,7 +82,7 @@ Optionally, you can create classes for your tables that extend the parent table
<?php // src/Model/Table/ChefsTable.php
namespace App\Model\Table;

class ChefsTable extends CooksTable
class ChefsTable extends CooksTable
{
// ...
}
Expand All @@ -107,25 +101,25 @@ public function validationChefs(Validator $validator)
```

### New entities
The behavior will automatically add helper methods for creating entities of different types

The behavior will automatically add helper methods for creating entities of different types
(i.e. `newChef()`). There are different ways of creating new entities, all are valid and depending
on the cases, you might need one or the other:

```php
// using the parent table
$cooks->newChef([...]);

// or, using the parent table again
$cooks->newEntity(['type' => 'chef', ...]);

// or, using the child table
$chefs->newEntity([...]);
```

### Note

For the above examples to work using (*chef), you need to add a custom rule to the `Inflector`:
For the above examples to work using (*chef), you need to add a custom rule to the `Inflector`:

```php
Cake\Utility\Inflector::rules('plural', ['/chef$/i' => '\1Chefs']);
Expand All @@ -148,7 +142,7 @@ https://github.com/usemuffin/sti/issues

## License

Copyright (c) 2015, [Use Muffin][muffin] and licensed under [The MIT License][mit].
Copyright (c) 2015-Present, [Use Muffin][muffin] and licensed under [The MIT License][mit].

[cakephp]:http://cakephp.org
[composer]:http://getcomposer.org
Expand Down
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

14 changes: 5 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "muffin/sti",
"description": "Single Table Inheritance for CakePHP 3 ORM",
"description": "Single Table Inheritance for CakePHP ORM",
"type": "cakephp-plugin",
"keywords": [
"cakephp",
Expand Down Expand Up @@ -30,11 +30,12 @@
"source": "https://github.com/usemuffin/sti"
},
"require": {
"php": ">=5.6",
"cakephp/cakephp": "^3.6"
},
"require-dev": {
"cakephp/cakephp": "~3.0",
"cakephp/cakephp-codesniffer": "2.*",
"phpunit/phpunit": "4.1.*"
"cakephp/cakephp-codesniffer": "^3.0",
"phpunit/phpunit": "^5.7.14|^6.0"
},
"autoload": {
"psr-4": {
Expand All @@ -46,10 +47,5 @@
"Muffin\\Sti\\Test\\": "tests",
"Muffin\\Sti\\TestApp\\": "tests/test_app"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
}
}
6 changes: 6 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
level: 6
checkGenericClassInNonGenericObjectType: false
checkMissingIterableValueType: false
ignoreErrors:

22 changes: 11 additions & 11 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
bootstrap="./tests/bootstrap.php"
colors="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./tests/bootstrap.php"
>
<php>
<ini name="memory_limit" value="-1"/>
</php>

<testsuites>
<testsuite name="{{pluginName}} Test Cases">
<directory>./tests/</directory>
<testsuite name="Sti TestSuite">
<directory>./tests/TestCase</directory>
</testsuite>
</testsuites>

Expand All @@ -22,14 +27,9 @@
</listener>
</listeners>

<!-- Prevent coverage reports from looking in tests and vendors -->
<filter>
<blacklist>
<directory suffix=".php">./vendor/</directory>
<directory suffix=".ctp">./vendor/</directory>

<directory suffix=".php">./tests/</directory>
<directory suffix=".ctp">./tests/</directory>
</blacklist>
<whitelist>
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
</phpunit>
Loading

0 comments on commit 529841c

Please sign in to comment.