Skip to content

Commit

Permalink
Merge pull request #6 from s3b4stian/analysis-qonYy7
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
s3b4stian authored Feb 19, 2017
2 parents 62299c9 + ffd116e commit c25461a
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 40 deletions.
12 changes: 6 additions & 6 deletions src/Linna/DI/DIResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ public function rules(array $rules)
public function resolve(string $class, array $rules = [])
{
$this->rules = array_merge($this->rules, $rules);
$class = (strpos($class, '\\') !== 0) ? '\\' . $class : $class;

$class = (strpos($class, '\\') !== 0) ? '\\'.$class : $class;

$this->buildTree($class);

$this->buildObjects();

return $this->cache[$class] ?? null;
}

Expand Down Expand Up @@ -153,7 +153,7 @@ private function buildTree(string $class)
private function buildObjects()
{
//deep dependency level, start to array end for not use array_reverse
for($i = count($this->dependencyTree) - 1; $i >= 0; $i--) {
for ($i = count($this->dependencyTree) - 1; $i >= 0; $i--) {

//class
foreach ($this->dependencyTree[$i] as $class => $dependency) {
Expand Down
28 changes: 14 additions & 14 deletions src/Linna/Http/FrontController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ class FrontController
* @var object Contain controller object
*/
private $route;

/**
* @var string Contain Controller and View action name
*/
private $routeAction;

/**
* @var array Paremeter passed to Controller
*/
private $routeParam;

/**
* Constructor.
*
Expand All @@ -61,10 +61,10 @@ class FrontController
public function __construct(RouteInterface $route, Model $model, View $view, Controller $controller)
{
$this->route = $route;

$this->routeAction = $route->getAction();
$this->routeParam = $route->getParam();

$this->model = $model;
$this->view = $view;
$this->controller = $controller;
Expand All @@ -80,38 +80,37 @@ public function run()

//run action before controller
$this->beforeAfterControllerAction('before');

//run controller
$this->runController();

//run action after controller
$this->beforeAfterControllerAction('after');

//notify model changes to view
$this->model->notify();

//run view
$this->runView();
}

/**
* Run action before or after controller execution
* Run action before or after controller execution.
*/
private function beforeAfterControllerAction(string $when)
{
//check for before action method
if (method_exists($this->controller, $when)) {
$this->controller->before();
}

$actionMethod = $when.ucfirst($this->routeAction);

if (method_exists($this->controller, $actionMethod) && $actionMethod !== $when)
{

if (method_exists($this->controller, $actionMethod) && $actionMethod !== $when) {
call_user_func([$this->controller, $actionMethod]);
}
}

/**
* Run controller.
*/
Expand All @@ -124,6 +123,7 @@ private function runController()
//action - call controller passing params
if (count($routeParam) > 0 && $routeAction !== '') {
call_user_func_array([$this->controller, $routeAction], $routeParam);

return;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/FOO/FOOController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ public function __construct(FOOModel $model)
{
parent::__construct($model);
}

public function modifyData()
{
$this->model->modifyData();
}

public function modifyDataFromParam($passedData)
{
$this->model->modifyDataFromParam($passedData);
Expand Down
4 changes: 2 additions & 2 deletions tests/FOO/FOOControllerBeforeAfter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function beforeModifyDataTimed()
{
$this->model->addToData('before');
}

public function modifyDataTimed()
{
$this->model->modifyDataTimed();
Expand All @@ -34,7 +34,7 @@ public function afterModifyDataTimed()
{
$this->model->addToData('after');
}

public function before()
{
//do nothing
Expand Down
10 changes: 5 additions & 5 deletions tests/FOO/FOOModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ public function __construct()

public function addToData(string $when)
{
if (!isset($this->getUpdate['data']))
{
if (!isset($this->getUpdate['data'])) {
$this->getUpdate = ['data' => 100];

return;
}

$this->getUpdate['data'] += 3;
}

public function modifyDataTimed()
{
$this->getUpdate['data'] += 20;
}

public function modifyData()
{
$this->getUpdate = ['data' => 1234];
Expand Down
2 changes: 1 addition & 1 deletion tests/FOO/FOOView.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function modifyData()
{
//$this->template = $this->htmlTemplate;
}

public function modifyDataTimed()
{
//$this->template = $this->htmlTemplate;
Expand Down
20 changes: 10 additions & 10 deletions tests/Http/FrontControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class FrontControllerTest extends TestCase
protected $routes;

protected $router;

public function setUp()
{
$routes = [];
Expand All @@ -37,7 +37,7 @@ public function setUp()
'controller' => 'FOOController',
'action' => '',
];

$routes[] = [
'name' => 'Foo',
'method' => 'GET',
Expand All @@ -47,7 +47,7 @@ public function setUp()
'controller' => 'FOOController',
'action' => '',
];

$routes[] = [
'name' => 'Foo',
'method' => 'GET',
Expand All @@ -57,8 +57,8 @@ public function setUp()
'controller' => 'FOOController',
'action' => '',
];
$routes[] = [

$routes[] = [
'name' => 'Foo',
'method' => 'GET',
'url' => '/Foo/(modifyDataTimed)',
Expand All @@ -67,7 +67,7 @@ public function setUp()
'controller' => 'FOOControllerBeforeAfter',
'action' => '',
];

//start router
$this->router = new Router($routes, [
'basePath' => '/',
Expand Down Expand Up @@ -193,8 +193,8 @@ public function testModelDetach()
$this->assertInstanceOf(stdClass::class, $test);
$this->assertEquals(false, isset($test->data));
}
/**

/**
* @depends testNewFrontController
*/
public function testRunFrontControllerWithActions()
Expand All @@ -217,9 +217,9 @@ public function testRunFrontControllerWithActions()
$FrontController->response();

$test = json_decode(ob_get_contents());

var_dump($test);

ob_end_clean();

$this->assertInstanceOf(stdClass::class, $test);
Expand Down

0 comments on commit c25461a

Please sign in to comment.