Skip to content

Commit

Permalink
Merge branch 'release/v0.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
jstoone committed Jan 23, 2017
2 parents cdd3df6 + afbca61 commit 3ef04dd
Show file tree
Hide file tree
Showing 21 changed files with 244 additions and 189 deletions.
28 changes: 28 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
engines:
duplication:
enabled: true
config:
languages:
- php
fixme:
enabled: true
phpmd:
enabled: true
config:
rulesets: ".phpmd.xml"
phpcodesniffer:
enabled: true
config:
standard: "PSR2"
checks:
PSR1 Classes ClassDeclaration MissingNamespace:
enabled: false
PSR1 Files SideEffects FoundWithSymbols:
enabled: false
ratings:
paths:
- "**.php"
exclude_paths:
- migrations/

11 changes: 11 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

$finder = Symfony\CS\Finder\DefaultFinder::create()
->exclude('vendor')
->exclude('node_modules')
->in(__DIR__);

return Symfony\CS\Config\Config::create()
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
->fixers(['ordered_use', '-psr0'])
->finder($finder);
34 changes: 34 additions & 0 deletions .phpmd.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0"?>
<ruleset name="PHPMD Ruleset for Dixie"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0
http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<rule ref="rulesets/cleancode.xml">
<exclude name="StaticAccess" />
</rule>
<rule ref="rulesets/codesize.xml" />
<rule ref="rulesets/controversial.xml" />
<rule ref="rulesets/design.xml" />
<rule ref="rulesets/naming.xml" />
<rule ref="rulesets/naming.xml/LongVariable">
<properties>
<property name="maximum" value="30" />
</properties>
</rule>
<rule ref="rulesets/naming.xml/ShortMethodName">
<properties>
<property name="exceptions" value="up" />
</properties>
</rule>
<rule ref="rulesets/codesize.xml/TooManyPublicMethods">
<properties>
<property name="ignorepattern" value="(^(set|get|test))i"/>
</properties>
</rule>
<rule ref="rulesets/unusedcode.xml">
<exclude name="UnusedFormalParameter" />
</rule>
</ruleset>

3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ matrix:
- php: 7.1
fast_finish: true

sudo: false

cache:
directories:
- $HOME/.composer/cache
Expand All @@ -23,3 +21,4 @@ install:
- travis_retry composer install --no-interaction --prefer-dist --no-suggest

script: vendor/bin/phpunit

3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"mockery/mockery": "^0.9.5"
},
"require-dev": {
"phpunit/phpunit": "^5.6"
"phpunit/phpunit": "^5.6",
"orchestra/testbench": "~3.3"
},
"autoload": {
"psr-4": {
Expand Down
8 changes: 4 additions & 4 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="tests/bootstrap.php"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
syntaxCheck="true"
verbose="true"
>
<testsuites>
<testsuite name="LaravelModelFuture Test Suite">
<testsuite name="Dixie Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
Expand Down
9 changes: 4 additions & 5 deletions src/Collections/FutureCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class FutureCollection extends EloquentCollection
*/
public function original()
{
return $this->map(function($item) {
return $this->map(function ($item) {
return $item->futureable;
});;
});
}

/**
Expand All @@ -27,7 +27,7 @@ public function result()
{
$model = $this->first()->futureable;

return $this->reduce(function($carry, $item) {
return $this->reduce(function ($carry, $item) {
return $carry->forceFill($item->data);
}, $model);
}
Expand All @@ -39,8 +39,7 @@ public function result()
*/
public function resultDiff()
{
return $this->map(function($item) {

return $this->map(function ($item) {
$before = $item->futureable->first(array_keys($item->data));

return [
Expand Down
21 changes: 5 additions & 16 deletions src/Commands/CommitToFutureCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,6 @@ class CommitToFutureCommand extends Command
*/
protected $description = 'A command to automatically commit future plans.';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();

}

/**
* Execute the console command.
*
Expand All @@ -42,17 +31,17 @@ public function handle()
{
$today = Carbon::now();
$futures = Future::with('futureable')
->forDate($today)
->untilDate($today)
->uncommitted()
->get();


if($futures->isEmpty()) {
if ($futures->isEmpty()) {
$this->outputMessage('No future plans for today.');
return;
}

$futures->each(function(Future $future) use ($today) {
$futures->each(function (Future $future) use ($today) {
$modelWithFuture = $future->futureable;

$modelWithFuture->future()
Expand All @@ -73,11 +62,11 @@ private function outputMessage($message)
{
$laravel = $this->laravel ?: false;

if( ! $laravel) {
if (! $laravel) {
return;
}

if( ! $laravel->runningInConsole()) {
if (! $laravel->runningInConsole()) {
return;
}

Expand Down
1 change: 0 additions & 1 deletion src/Contracts/ModelFuture.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ interface ModelFuture
* @return Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function futures();

}
3 changes: 1 addition & 2 deletions src/FuturePlanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function at(Carbon $futureDate)
*/
public function see(Carbon $futureDate)
{
return $this->getPlansFor($futureDate)->result();
return $this->getPlansUntil($futureDate)->result();
}

/**
Expand Down Expand Up @@ -157,5 +157,4 @@ public function hasAnyPlansUntil(Carbon $futureDate)
{
return (bool) $this->getPlansUntil($futureDate)->count();
}

}
5 changes: 1 addition & 4 deletions src/Models/Future.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,7 @@ public function scopeForDate(Builder $query, Carbon $date)
*/
public function scopeUntilDate(Builder $query, Carbon $date)
{
$today = Carbon::now()->toDateString();

return $query->where('commit_at', '>=', $today)
->where('commit_at', '<=', $date);
return $query->whereDate('commit_at', '<=', $date->toDateString());
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
use Dixie\EloquentModelFuture\Commands\CommitToFutureCommand;


class ServiceProvider extends BaseServiceProvider
{

Expand All @@ -18,7 +17,7 @@ public function boot()
{
$this->loadMigrationsFrom(__DIR__.'/../migrations');

if($this->app->runningInConsole()) {
if ($this->app->runningInConsole()) {
$this->commands(CommitToFutureCommand::class);
}
}
Expand All @@ -31,5 +30,4 @@ public function boot()
public function register()
{
}

}
10 changes: 6 additions & 4 deletions src/Traits/HasFuture.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ trait HasFuture
public function futures()
{
return $this->morphMany(
Future::class,
'futures', 'futureable_type', 'futureable_id'
Future::class,
'futures',
'futureable_type',
'futureable_id'
);
}

Expand Down Expand Up @@ -49,7 +51,7 @@ public function future()
*/
public function commit()
{
$this->future()->getPlansFor(Carbon::now())
$this->future()->getPlansUntil(Carbon::now())
->each([$this, 'commitFuturePlan']);

return $this->save();
Expand All @@ -62,7 +64,7 @@ public function commit()
*/
public function commitFuturePlan(Future $futurePlan)
{
$futurePlan->committed_at = Carbon::now();;
$futurePlan->committed_at = Carbon::now();

return $futurePlan->save();
}
Expand Down
75 changes: 75 additions & 0 deletions tests/Models/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace Dixie\EloquentModelFuture\Tests\Models;

use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Dixie\EloquentModelFuture\Contracts\ModelFuture;

class User extends Model implements ModelFuture, Authenticatable
{
use \Dixie\EloquentModelFuture\Traits\HasFuture;

protected $table = 'users';

protected $guarded = [];

/**
* Get the name of the unique identifier for the user.
*
* @return string
*/
public function getAuthIdentifierName()
{
return $this->name;
}

/**
* Get the unique identifier for the user.
*
* @return mixed
*/
public function getAuthIdentifier()
{
return $this->id;
}

/**
* Get the password for the user.
*
* @return string
*/
public function getAuthPassword()
{
return $this->name;
}

/**
* Get the token value for the "remember me" session.
*
* @return string
*/
public function getRememberToken()
{
return 'token';
}

/**
* Set the token value for the "remember me" session.
*
* @param string $value
*/
public function setRememberToken($value)
{
}

/**
* Get the column name for the "remember me" token.
*
* @return string
*/
public function getRememberTokenName()
{
return 'tokenName';
}
}
Loading

0 comments on commit 3ef04dd

Please sign in to comment.