Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StopwatchTask should use DispatchTask #991

Merged
merged 1 commit into from
Nov 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 7 additions & 45 deletions classes/phing/tasks/ext/StopwatchTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
* <http://phing.info>.
*/

use Symfony\Component\Stopwatch\Stopwatch;

/**
* Stopwatch.
*
* @author Siad Ardroumli <siad.ardroumli@gmail.com>
* @package phing.tasks.ext.stopwatch
*/
class StopwatchTask extends Task
class StopwatchTask extends DispatchTask
{
/**
* Name of the timer.
Expand All @@ -40,13 +41,6 @@ class StopwatchTask extends Task
*/
private $category = '';

/**
* Timer action.
*
* @var string $action
*/
private $action = 'start';

/**
* Holds an instance of Stopwatch.
*
Expand All @@ -61,36 +55,22 @@ class StopwatchTask extends Task
*/
public function init()
{
}

/**
* Load stopwatch.
*
* @return void
*
* @throws BuildException
*/
private function loadStopwatch()
{
@include_once 'Symfony/Component/Stopwatch/autoload.php';
@include_once 'Symfony/Component/Stopwatch/autoloader.php';
@include_once 'vendor/autoload.php';

if (!class_exists('\\Symfony\\Component\\Stopwatch\\Stopwatch')) {
throw new BuildException("StopwatchTask requires symfony/stopwatch to be installed.");
}

$this->setAction('start');
}

/**
* Get the stopwatch instance.
*
* @return \Symfony\Component\Stopwatch\Stopwatch
* @return Stopwatch
*/
private function getStopwatchInstance()
{
if (self::$timer === null) {
$stopwatch = '\\Symfony\\Component\\Stopwatch\\Stopwatch';
self::$timer = new $stopwatch;
self::$timer = new Stopwatch();
}

return self::$timer;
Expand Down Expand Up @@ -165,22 +145,6 @@ public function setCategory($category)
$this->category = $category;
}

/**
* Set the action.
* Action could be one of
* - start
* - lap
* - stop
*
* @param string $action
*
* @return void
*/
public function setAction($action)
{
$this->action = $action;
}

/**
* The main entry point
*
Expand All @@ -190,9 +154,7 @@ public function setAction($action)
*/
public function main()
{
$this->loadStopwatch();

switch ($this->action) {
switch ($this->getAction()) {
case "start":
$this->start();
break;
Expand Down