Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jarektkaczyk committed Dec 5, 2020
1 parent 87d26bd commit 5ec4d3e
Show file tree
Hide file tree
Showing 14 changed files with 365 additions and 372 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Tests

on: [push, pull_request]

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [7.4]
dependency-version: [prefer-stable]

name: P${{ matrix.php }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Cache dependencies
uses: actions/cache@v1
with:
path: ~/.composer/cache/files
key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: pcov

- name: Install dependencies
run: |
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
composer require satooshi/php-coveralls:~0.6@stable
mkdir -p build/logs
- name: Execute tests
run: |
vendor/bin/phpunit --coverage-clover build/logs/clover.xml
vendor/bin/coveralls -v
71 changes: 71 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php


$finder = PhpCsFixer\Finder::create()
->in(__DIR__ . '/src/');

return PhpCsFixer\Config::create()
->setFinder($finder)
->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'combine_consecutive_unsets' => true,
'method_separation' => true,
'no_multiline_whitespace_before_semicolons' => true,
'single_quote' => true,
'blank_line_before_return' => true,
'combine_consecutive_issets' => true,
'compact_nullable_typehint' => true,
'concat_space' => array('spacing' => 'one'),
'declare_equal_normalize' => true,
'function_typehint_space' => true,
'hash_to_slash_comment' => true,
'include' => true,
'lowercase_cast' => true,
'no_multiline_whitespace_around_double_arrow' => true,
'no_spaces_around_offset' => true,
'no_unused_imports' => true,
'no_whitespace_before_comma_in_array' => true,
'no_whitespace_in_blank_line' => true,
'object_operator_without_whitespace' => true,
'php_unit_fqcn_annotation' => true,
'phpdoc_no_package' => true,
'phpdoc_scalar' => true,
'phpdoc_single_line_var_spacing' => true,
'protected_to_private' => true,
'return_assignment' => true,
'single_blank_line_before_namespace' => true,
'single_line_after_imports' => true,
'single_class_element_per_statement' => true,
'ternary_operator_spaces' => true,
'trailing_comma_in_multiline_array' => true,
'trim_array_spaces' => true,
'unary_operator_spaces' => true,
'whitespace_after_comma_in_array' => true,
'no_null_property_initialization' => true,
'binary_operator_spaces' => [
'default' => 'single_space',
],
'class_attributes_separation' => [
'elements' => ['method'],
],
'method_argument_space' => [
'keep_multiple_spaces_after_comma' => true,
],
'braces' => [
'allow_single_line_closure' => false,
'position_after_anonymous_constructs' => 'same',
'position_after_control_structures' => 'same',
'position_after_functions_and_oop_constructs' => 'next',
],
'no_extra_consecutive_blank_lines' => [
'curly_brace_block',
'extra',
'parenthesis_brace_block',
'square_brace_block',
'throw',
'use',
],
])
->setLineEnding("\n")
;
20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
}
],
"require": {
"php": ">=7.0.0",
"php": ">=7.1.0",
"sofa/eloquence-base": ">=5.5",
"sofa/eloquence-mutable": ">=5.5"
},
"require-dev": {
"phpunit/phpunit": "4.5.0",
"phpunit/phpunit": "^9.0",
"squizlabs/php_codesniffer": "2.3.3",
"mockery/mockery": "0.9.4"
"mockery/mockery": "^1.0",
"friendsofphp/php-cs-fixer": "^2.0"
},
"autoload": {
"psr-4": {
Expand Down
31 changes: 18 additions & 13 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.0/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
verbose="true"
cacheResultFile=".phpunit.cache/test-results"
failOnRisky="true"
failOnWarning="true">
<testsuites>
<testsuite name="Eloquence">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>

<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true"
ignoreDeprecatedCodeUnits="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>

<php>
<const name="PHPUNIT_TESTSUITE" value="true"/>
</php>
</phpunit>
9 changes: 5 additions & 4 deletions src/Metable.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static function bootMetable()
* Determine wheter method called on the query is customizable by this trait.
*
* @param string $method
* @return boolean
* @return bool
*/
protected function isMetaQueryable($method)
{
Expand Down Expand Up @@ -198,7 +198,6 @@ protected function metaSingleResult(Builder $query, $method, $alias)
return $query->getQuery()->select("{$alias}.meta_value")->{$method}("{$alias}.meta_value");
}


/**
* Join meta attributes table.
*
Expand Down Expand Up @@ -374,7 +373,7 @@ protected function saveMeta()
* Determine whether meta attribute is allowed for the model.
*
* @param string $key
* @return boolean
* @return bool
*/
public function allowsMeta($key)
{
Expand All @@ -387,7 +386,7 @@ public function allowsMeta($key)
* Determine whether meta attribute exists on the model.
*
* @param string $key
* @return boolean
* @return bool
*/
public function hasMeta($key)
{
Expand All @@ -404,6 +403,7 @@ public function getMeta($key)
{
return $this->getMetaAttributes()->getValue($key);
}

/**
* Get meta attribute values by group.
*
Expand All @@ -414,6 +414,7 @@ public function getMetaByGroup($group)
{
return $this->getMetaAttributes()->getMetaByGroup($group);
}

/**
* Set meta attribute.
*
Expand Down
21 changes: 12 additions & 9 deletions src/Metable/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Attribute extends Model implements AttributeContract
/**
* Indicates if the model should be timestamped.
*
* @var boolean
* @var bool
*/
public $timestamps = false;

Expand All @@ -51,19 +51,19 @@ class Attribute extends Model implements AttributeContract
* @var array
*/
protected $getterMutators = [
'array' => 'json_decode',
'StdClass' => 'json_decode',
'DateTime' => 'asDateTime',
'array' => 'json_decode',
'StdClass' => 'json_decode',
'DateTime' => 'asDateTime',
Model::class => 'unserialize',
];

/**
* @var array
*/
protected $setterMutators = [
'array' => 'json_encode',
'StdClass' => 'json_encode',
'DateTime' => 'fromDateTime',
'array' => 'json_encode',
'StdClass' => 'json_encode',
'DateTime' => 'fromDateTime',
Model::class => 'serialize',
];

Expand Down Expand Up @@ -172,6 +172,7 @@ public function getMetaGroup()
{
return $this->attributes['meta_group'];
}

/**
* Cast value to proper type.
*
Expand Down Expand Up @@ -205,6 +206,7 @@ protected function setMetaKey($key)

$this->attributes['meta_key'] = $key;
}

/**
* Set group of the meta attribute.
*
Expand All @@ -220,6 +222,7 @@ public function setMetaGroup($group = null)

$this->attributes['meta_group'] = $group;
}

/**
* Set type of the meta attribute.
*
Expand Down Expand Up @@ -276,7 +279,7 @@ protected function mutateValue($value, $dir = 'setter')
* Determine whether the value type can be set to string.
*
* @param mixed $value
* @return boolean
* @return bool
*/
protected function isStringable($value)
{
Expand Down Expand Up @@ -318,7 +321,7 @@ protected function getMutatedType($value, $dir = 'setter')
*
* @param mixed $value
* @param string $dir
* @return boolean
* @return bool
*/
protected function hasMutator($value, $dir = 'setter', $type = null)
{
Expand Down
5 changes: 3 additions & 2 deletions src/Metable/AttributeBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Sofa\Eloquence\Metable;

use InvalidArgumentException;
use Illuminate\Database\Eloquent\Collection;
use Sofa\Eloquence\Contracts\AttributeBag as AttributeBagContract;

Expand Down Expand Up @@ -123,6 +122,7 @@ public function getValue($key)
return $attribute->getValue();
}
}

/**
* Get attribute values by group.
*
Expand All @@ -133,6 +133,7 @@ public function getMetaByGroup($group)
{
return $this->where('meta_group', $group);
}

/**
* Get collection as key-value array.
*
Expand Down Expand Up @@ -209,7 +210,7 @@ public function __get($key)
* Handle isset calls.
*
* @param string $key
* @return boolean
* @return bool
*/
public function __isset($key)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Metable/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/**
* This class provides instance scope for the closures
* so they can be rebound later onto the acutal model.
* so they can be rebound later onto the actual model.
*/
class Hooks
{
Expand Down Expand Up @@ -139,7 +139,7 @@ public function queryHook()
{
return function ($next, $query, $bag) {
$method = $bag->get('method');
$args = $bag->get('args');
$args = $bag->get('args');
$column = $args->get('column');

if (!$this->hasColumn($column) && $this->allowsMeta($column) && $this->isMetaQueryable($method)) {
Expand All @@ -156,8 +156,8 @@ public function queryHook()

public function __call($method, $params)
{
if (strpos($method, '__') === 0 && method_exists($this, $method.'Hook')) {
return call_user_func_array([$this, $method.'Hook'], $params);
if (strpos($method, '__') === 0 && method_exists($this, $method . 'Hook')) {
return call_user_func_array([$this, $method . 'Hook'], $params);
}

throw new BadMethodCallException("Method [{$method}] doesn't exist on this object.");
Expand Down
1 change: 0 additions & 1 deletion src/Metable/InvalidMutatorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

class InvalidMutatorException extends \LogicException
{

}
1 change: 0 additions & 1 deletion src/Metable/InvalidTypeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

class InvalidTypeException extends \InvalidArgumentException
{

}
Loading

0 comments on commit 5ec4d3e

Please sign in to comment.