refactoring
This commit is contained in:
parent
79f779e520
commit
7053cb5740
@ -18,7 +18,6 @@ cache:
|
|||||||
- build
|
- build
|
||||||
|
|
||||||
php:
|
php:
|
||||||
- 5.4
|
|
||||||
- 5.5
|
- 5.5
|
||||||
- 5.6
|
- 5.6
|
||||||
- 7
|
- 7
|
||||||
@ -33,7 +32,6 @@ env:
|
|||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
allow_failures:
|
allow_failures:
|
||||||
- php: 7
|
|
||||||
- php: hhvm
|
- php: hhvm
|
||||||
|
|
||||||
install:
|
install:
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.4",
|
"php": ">=5.5",
|
||||||
"symfony/process": "^2.5",
|
"symfony/process": "^2.5",
|
||||||
"jms/serializer": "^1.0",
|
"jms/serializer": "^1.0",
|
||||||
"phpoption/phpoption": "^1.3",
|
"phpoption/phpoption": "^1.3",
|
||||||
|
@ -40,7 +40,7 @@ class CarbonHandler implements SubscribingHandlerInterface
|
|||||||
public static function getSubscribingMethods()
|
public static function getSubscribingMethods()
|
||||||
{
|
{
|
||||||
$methods = array();
|
$methods = array();
|
||||||
$types = array('Carbon\Carbon', 'Carbon');
|
$types = array(Carbon::class, 'Carbon');
|
||||||
|
|
||||||
foreach ($types as $type) {
|
foreach ($types as $type) {
|
||||||
$methods[] = array(
|
$methods[] = array(
|
||||||
|
@ -140,11 +140,20 @@ class TaskManager
|
|||||||
return new ArrayCollection($result);
|
return new ArrayCollection($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string|string[] $filter
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function count($filter = null)
|
||||||
|
{
|
||||||
|
return $this->taskwarrior->count($filter);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string|array $filter
|
* @param string|array $filter
|
||||||
* @return Task[]|ArrayCollection
|
* @return Task[]|ArrayCollection
|
||||||
*/
|
*/
|
||||||
public function filterPending($filter = null)
|
public function findPending($filter = null)
|
||||||
{
|
{
|
||||||
return $this->filter(array_merge((array)$filter, ['status:pending']));
|
return $this->filter(array_merge((array)$filter, ['status:pending']));
|
||||||
}
|
}
|
||||||
@ -275,7 +284,7 @@ class TaskManager
|
|||||||
* @return Task[]|ArrayCollection
|
* @return Task[]|ArrayCollection
|
||||||
* @throws Exception\ConfigException
|
* @throws Exception\ConfigException
|
||||||
*/
|
*/
|
||||||
public function filterByReport($report)
|
public function findByReport($report)
|
||||||
{
|
{
|
||||||
if (!$report instanceof Report) {
|
if (!$report instanceof Report) {
|
||||||
$report = $this->taskwarrior->config()->getReport($report);
|
$report = $this->taskwarrior->config()->getReport($report);
|
||||||
@ -292,9 +301,9 @@ class TaskManager
|
|||||||
* @return Task[]|ArrayCollection
|
* @return Task[]|ArrayCollection
|
||||||
* @throws Exception\ConfigException
|
* @throws Exception\ConfigException
|
||||||
*/
|
*/
|
||||||
public function filterByContext($context)
|
public function findByContext($context)
|
||||||
{
|
{
|
||||||
if (!$context instanceof Report) {
|
if (!$context instanceof Context) {
|
||||||
$context = $this->taskwarrior->config()->getContext($context);
|
$context = $this->taskwarrior->config()->getContext($context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -330,7 +339,7 @@ class TaskManager
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$task = $factory->createProxy('DavidBadura\Taskwarrior\Task', $initializer);
|
$task = $factory->createProxy(Task::class, $initializer);
|
||||||
|
|
||||||
return $this->tasks[$uuid] = $task;
|
return $this->tasks[$uuid] = $task;
|
||||||
}
|
}
|
||||||
@ -358,7 +367,7 @@ class TaskManager
|
|||||||
$json = $this->taskwarrior->export($filter);
|
$json = $this->taskwarrior->export($filter);
|
||||||
|
|
||||||
/** @var Task[] $tasks */
|
/** @var Task[] $tasks */
|
||||||
$tasks = $this->getSerializer()->deserialize($json, 'array<DavidBadura\Taskwarrior\Task>', 'json');
|
$tasks = $this->getSerializer()->deserialize($json, 'array<' . Task::class . '>', 'json');
|
||||||
|
|
||||||
foreach ($tasks as $task) {
|
foreach ($tasks as $task) {
|
||||||
if (!$task->getDependencies()) {
|
if (!$task->getDependencies()) {
|
||||||
@ -426,7 +435,7 @@ class TaskManager
|
|||||||
*/
|
*/
|
||||||
private function setValue(Task $task, $attr, $value)
|
private function setValue(Task $task, $attr, $value)
|
||||||
{
|
{
|
||||||
$refClass = new \ReflectionClass('DavidBadura\Taskwarrior\Task');
|
$refClass = new \ReflectionClass(Task::class);
|
||||||
$refProp = $refClass->getProperty($attr);
|
$refProp = $refClass->getProperty($attr);
|
||||||
$refProp->setAccessible(true);
|
$refProp->setAccessible(true);
|
||||||
$refProp->setValue($task, $value);
|
$refProp->setValue($task, $value);
|
||||||
|
@ -212,6 +212,16 @@ class Taskwarrior
|
|||||||
return $this->command('export', $filter);
|
return $this->command('export', $filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string|string[] $filter
|
||||||
|
* @return int
|
||||||
|
* @throws CommandException
|
||||||
|
*/
|
||||||
|
public function count($filter = null)
|
||||||
|
{
|
||||||
|
return (int)$this->command('count', $filter);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $command
|
* @param string $command
|
||||||
* @param string|string[] $filter
|
* @param string|string[] $filter
|
||||||
|
@ -57,7 +57,7 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testEmpty()
|
public function testEmpty()
|
||||||
{
|
{
|
||||||
$tasks = $this->taskManager->filterPending();
|
$tasks = $this->taskManager->findPending();
|
||||||
$this->assertEmpty($tasks);
|
$this->assertEmpty($tasks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,14 +164,14 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->taskManager->save($task);
|
$this->taskManager->save($task);
|
||||||
|
|
||||||
$this->assertEquals($uuid, $task->getUuid());
|
$this->assertEquals($uuid, $task->getUuid());
|
||||||
$this->assertCount(1, $this->taskManager->filterPending());
|
$this->assertCount(1, $this->taskManager->findPending());
|
||||||
|
|
||||||
$this->taskManager->clear();
|
$this->taskManager->clear();
|
||||||
|
|
||||||
$this->taskManager->save($task);
|
$this->taskManager->save($task);
|
||||||
|
|
||||||
$this->assertEquals($uuid, $task->getUuid());
|
$this->assertEquals($uuid, $task->getUuid());
|
||||||
$this->assertCount(1, $this->taskManager->filterPending());
|
$this->assertCount(1, $this->taskManager->findPending());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testClone()
|
public function testClone()
|
||||||
@ -180,12 +180,12 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$task->setDescription('foo');
|
$task->setDescription('foo');
|
||||||
|
|
||||||
$this->taskManager->save($task);
|
$this->taskManager->save($task);
|
||||||
$this->assertCount(1, $this->taskManager->filterPending());
|
$this->assertCount(1, $this->taskManager->findPending());
|
||||||
|
|
||||||
$task2 = clone $task;
|
$task2 = clone $task;
|
||||||
|
|
||||||
$this->taskManager->save($task2);
|
$this->taskManager->save($task2);
|
||||||
$this->assertCount(2, $this->taskManager->filterPending());
|
$this->assertCount(2, $this->taskManager->findPending());
|
||||||
|
|
||||||
$this->taskManager->done($task);
|
$this->taskManager->done($task);
|
||||||
$this->assertTrue($task->isCompleted());
|
$this->assertTrue($task->isCompleted());
|
||||||
@ -211,7 +211,7 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->taskManager->save($task1);
|
$this->taskManager->save($task1);
|
||||||
$this->taskManager->save($task2);
|
$this->taskManager->save($task2);
|
||||||
|
|
||||||
$result = $this->taskManager->filterPending();
|
$result = $this->taskManager->findPending();
|
||||||
|
|
||||||
$this->assertInstanceOf('Doctrine\Common\Collections\ArrayCollection', $result);
|
$this->assertInstanceOf('Doctrine\Common\Collections\ArrayCollection', $result);
|
||||||
$this->assertCount(2, $result);
|
$this->assertCount(2, $result);
|
||||||
@ -231,7 +231,7 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->taskManager->save($task1);
|
$this->taskManager->save($task1);
|
||||||
$this->taskManager->save($task2);
|
$this->taskManager->save($task2);
|
||||||
|
|
||||||
$this->assertCount(1, $this->taskManager->filterPending('project:home prio:H +now'));
|
$this->assertCount(1, $this->taskManager->findPending('project:home prio:H +now'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testModified()
|
public function testModified()
|
||||||
@ -323,7 +323,7 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals(Task::STATUS_PENDING, $result->getStatus());
|
$this->assertEquals(Task::STATUS_PENDING, $result->getStatus());
|
||||||
$this->assertTrue($result->isPending());
|
$this->assertTrue($result->isPending());
|
||||||
|
|
||||||
$this->assertCount(1, $this->taskManager->filterPending());
|
$this->assertCount(1, $this->taskManager->findPending());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDelete()
|
public function testDelete()
|
||||||
@ -331,17 +331,17 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$task1 = new Task();
|
$task1 = new Task();
|
||||||
$task1->setDescription('foo1');
|
$task1->setDescription('foo1');
|
||||||
|
|
||||||
$this->assertCount(0, $this->taskManager->filterPending());
|
$this->assertCount(0, $this->taskManager->findPending());
|
||||||
|
|
||||||
$this->taskManager->save($task1);
|
$this->taskManager->save($task1);
|
||||||
$this->assertCount(1, $this->taskManager->filter());
|
$this->assertCount(1, $this->taskManager->filter());
|
||||||
$this->assertCount(1, $this->taskManager->filterPending());
|
$this->assertCount(1, $this->taskManager->findPending());
|
||||||
$this->assertFalse($task1->isDeleted());
|
$this->assertFalse($task1->isDeleted());
|
||||||
$this->assertEquals(Task::STATUS_PENDING, $task1->getStatus());
|
$this->assertEquals(Task::STATUS_PENDING, $task1->getStatus());
|
||||||
|
|
||||||
$this->taskManager->delete($task1);
|
$this->taskManager->delete($task1);
|
||||||
$this->assertCount(1, $this->taskManager->filter());
|
$this->assertCount(1, $this->taskManager->filter());
|
||||||
$this->assertCount(0, $this->taskManager->filterPending());
|
$this->assertCount(0, $this->taskManager->findPending());
|
||||||
$this->assertTrue($task1->isDeleted());
|
$this->assertTrue($task1->isDeleted());
|
||||||
$this->assertEquals(Task::STATUS_DELETED, $task1->getStatus());
|
$this->assertEquals(Task::STATUS_DELETED, $task1->getStatus());
|
||||||
}
|
}
|
||||||
@ -351,17 +351,17 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$task1 = new Task();
|
$task1 = new Task();
|
||||||
$task1->setDescription('foo1');
|
$task1->setDescription('foo1');
|
||||||
|
|
||||||
$this->assertCount(0, $this->taskManager->filterPending());
|
$this->assertCount(0, $this->taskManager->findPending());
|
||||||
|
|
||||||
$this->taskManager->save($task1);
|
$this->taskManager->save($task1);
|
||||||
$this->assertCount(1, $this->taskManager->filter());
|
$this->assertCount(1, $this->taskManager->filter());
|
||||||
$this->assertCount(1, $this->taskManager->filterPending());
|
$this->assertCount(1, $this->taskManager->findPending());
|
||||||
$this->assertFalse($task1->isCompleted());
|
$this->assertFalse($task1->isCompleted());
|
||||||
$this->assertEquals(Task::STATUS_PENDING, $task1->getStatus());
|
$this->assertEquals(Task::STATUS_PENDING, $task1->getStatus());
|
||||||
|
|
||||||
$this->taskManager->done($task1);
|
$this->taskManager->done($task1);
|
||||||
$this->assertCount(1, $this->taskManager->filter());
|
$this->assertCount(1, $this->taskManager->filter());
|
||||||
$this->assertCount(0, $this->taskManager->filterPending());
|
$this->assertCount(0, $this->taskManager->findPending());
|
||||||
$this->assertTrue($task1->isCompleted());
|
$this->assertTrue($task1->isCompleted());
|
||||||
$this->assertEquals(Task::STATUS_COMPLETED, $task1->getStatus());
|
$this->assertEquals(Task::STATUS_COMPLETED, $task1->getStatus());
|
||||||
}
|
}
|
||||||
@ -469,9 +469,9 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->assertEquals($project, $task->getProject());
|
$this->assertEquals($project, $task->getProject());
|
||||||
|
|
||||||
$this->assertCount(1, $this->taskManager->filterPending());
|
$this->assertCount(1, $this->taskManager->findPending());
|
||||||
$this->assertCount(1, $this->taskManager->filterPending('project:' . $project));
|
$this->assertCount(1, $this->taskManager->findPending('project:' . $project));
|
||||||
$this->assertCount(0, $this->taskManager->filterPending('project:emtpy_project'));
|
$this->assertCount(0, $this->taskManager->findPending('project:emtpy_project'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testProjects()
|
public function testProjects()
|
||||||
@ -542,8 +542,8 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$task1 = $this->taskManager->find($task1->getUuid());
|
$task1 = $this->taskManager->find($task1->getUuid());
|
||||||
$this->assertEquals(array('b', 'c', 'd'), $task1->getTags());
|
$this->assertEquals(array('b', 'c', 'd'), $task1->getTags());
|
||||||
$this->assertCount(0, $this->taskManager->filterPending('+a'));
|
$this->assertCount(0, $this->taskManager->findPending('+a'));
|
||||||
$this->assertCount(1, $this->taskManager->filterPending('+b'));
|
$this->assertCount(1, $this->taskManager->findPending('+b'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTagUnicode()
|
public function testTagUnicode()
|
||||||
@ -559,7 +559,7 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals(array('später'), $task1->getTags());
|
$this->assertEquals(array('später'), $task1->getTags());
|
||||||
$this->assertEquals(array('später'), $this->taskwarrior->tags());
|
$this->assertEquals(array('später'), $this->taskwarrior->tags());
|
||||||
|
|
||||||
$this->assertCount(1, $this->taskManager->filterPending('+später'));
|
$this->assertCount(1, $this->taskManager->findPending('+später'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTagNameNotAllowed()
|
public function testTagNameNotAllowed()
|
||||||
@ -589,12 +589,12 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->taskManager->save($task1);
|
$this->taskManager->save($task1);
|
||||||
$this->assertTrue($task1->isWaiting());
|
$this->assertTrue($task1->isWaiting());
|
||||||
|
|
||||||
$this->assertCount(0, $this->taskManager->filterPending());
|
$this->assertCount(0, $this->taskManager->findPending());
|
||||||
$this->assertCount(1, $this->taskManager->filter('status:waiting'));
|
$this->assertCount(1, $this->taskManager->filter('status:waiting'));
|
||||||
|
|
||||||
sleep(3);
|
sleep(3);
|
||||||
|
|
||||||
$this->assertCount(1, $this->taskManager->filterPending());
|
$this->assertCount(1, $this->taskManager->findPending());
|
||||||
$this->assertFalse($task1->isWaiting());
|
$this->assertFalse($task1->isWaiting());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -611,7 +611,7 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->assertTrue($task1->isRecurring());
|
$this->assertTrue($task1->isRecurring());
|
||||||
|
|
||||||
$result = $this->taskManager->filterPending();
|
$result = $this->taskManager->findPending();
|
||||||
$this->assertCount(1, $result);
|
$this->assertCount(1, $result);
|
||||||
|
|
||||||
$this->assertTrue($result[0]->isPending());
|
$this->assertTrue($result[0]->isPending());
|
||||||
@ -732,11 +732,11 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->taskManager->save($task1);
|
$this->taskManager->save($task1);
|
||||||
|
|
||||||
$this->assertCount(1, $this->taskManager->filterPending());
|
$this->assertCount(1, $this->taskManager->findPending());
|
||||||
|
|
||||||
sleep(3);
|
sleep(3);
|
||||||
|
|
||||||
$this->assertCount(0, $this->taskManager->filterPending());
|
$this->assertCount(0, $this->taskManager->findPending());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -797,7 +797,7 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->taskManager->save($task1);
|
$this->taskManager->save($task1);
|
||||||
$this->assertCount(1, $this->taskManager->filter('(status:pending or status:waiting)'));
|
$this->assertCount(1, $this->taskManager->filter('(status:pending or status:waiting)'));
|
||||||
$this->assertCount(1, $this->taskManager->filterPending('(status:pending or status:waiting)'));
|
$this->assertCount(1, $this->taskManager->findPending('(status:pending or status:waiting)'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDependenciesException()
|
public function testDependenciesException()
|
||||||
@ -913,6 +913,21 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('foo', $task->getDescription());
|
$this->assertEquals('foo', $task->getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCount()
|
||||||
|
{
|
||||||
|
$this->assertEquals(0, $this->taskManager->count());
|
||||||
|
|
||||||
|
$task = new Task();
|
||||||
|
$task->setDescription('foo');
|
||||||
|
$task->addTag('bar');
|
||||||
|
|
||||||
|
$this->taskManager->save($task);
|
||||||
|
|
||||||
|
$this->assertEquals(1, $this->taskManager->count());
|
||||||
|
$this->assertEquals(1, $this->taskManager->count('+bar'));
|
||||||
|
$this->assertEquals(0, $this->taskManager->count('+baz'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $string
|
* @param string $string
|
||||||
* @return \DateTime
|
* @return \DateTime
|
||||||
|
Loading…
Reference in New Issue
Block a user