Skip to content

Commit

Permalink
Merge pull request #30 from koriym/phpstan
Browse files Browse the repository at this point in the history
Soothe phpstan
  • Loading branch information
koriym authored May 30, 2018
2 parents 44254ca + 640a8b0 commit 90aed38
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 35 deletions.
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: php
sudo: false
dist: trusty
php:
- 7.0
- 7
- 7.1
- 7.2
cache:
Expand All @@ -16,9 +16,11 @@ env:
before_script:
- composer self-update
- composer update $DEPENDENCIES
- if [[ $TRAVIS_PHP_VERSION = '7.1' && DEPENDENCIES = '' ]]; then COVERAGE="--coverage-clover=coverage.clover"; else phpenv config-rm xdebug.ini; fi
- if [[ $TRAVIS_PHP_VERSION = '7.1' && DEPENDENCIES = '' ]]; then composer require --dev phpstan/phpstan-shim friendsofphp/php-cs-fixer; fi
script:
- ./vendor/bin/phpunit --coverage-clover=coverage.clover;
- ./vendor/bin/phpunit $COVERAGE;
- if [ "$TRAVIS_PHP_VERSION" = "7.1" ]; then wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.4.0/php-cs-fixer.phar -O php-cs-fixer && php php-cs-fixer fix --config=.php_cs -v --dry-run --using-cache=no --path-mode=intersection `git diff --name-only --diff-filter=ACMRTUXB $TRAVIS_COMMIT_RANGE`; fi

- if [[ $TRAVIS_PHP_VERSION = '7.1' && DEPENDENCIES = '' ]]; then ./vendor/bin/phpstan analyse -l max src tests --no-progress --no-interaction; fi
after_script:
- if [ "$TRAVIS_PHP_VERSION" = "7.1" ]; then wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@
}
},
"autoload-dev":{
"psr-4":{
"Madapaja\\TwigModule\\": "tests/Fake/src"
"psr-4": {
"Madapaja\\TwigModule\\": [
"tests",
"tests/Fake/src"
]
}
},
"scripts": {
Expand Down
Empty file added phpstan.neon
Empty file.
2 changes: 1 addition & 1 deletion src/MobileTemplateFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct($userAgent = '', array $paths = [])
*/
public function __invoke(string $name) : string
{
$templatePath = $this->templateFinder->__invoke($name);
$templatePath = ($this->templateFinder)($name);
$detect = new \Mobile_Detect(null, $this->userAgent);
$isMobile = $detect->isMobile() && ! $detect->isTablet();
if ($isMobile) {
Expand Down
8 changes: 3 additions & 5 deletions src/TwigRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,10 @@ private function load(ResourceObject $ro)
try {
return $this->loadTemplate($ro);
} catch (\Twig_Error_Loader $e) {
if ($ro->code !== 200) {
return;
if ($ro->code === 200) {
throw new Exception\TemplateNotFound($e->getMessage(), 500, $e);
}
}

throw new Exception\TemplateNotFound($e->getMessage(), 500, $e);
}

private function isNoContent(ResourceObject $ro) : bool
Expand All @@ -88,7 +86,7 @@ private function loadTemplate(ResourceObject $ro) : \Twig_TemplateWrapper
$loader = $this->twig->getLoader();
if ($loader instanceof \Twig_Loader_Filesystem) {
$classFile = $this->getReflection($ro)->getFileName();
$templateFile = $this->templateFinder->__invoke($classFile);
$templateFile = ($this->templateFinder)($classFile);

return $this->twig->load($templateFile);
}
Expand Down
6 changes: 2 additions & 4 deletions tests/AppMetaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@
*
* @license http://opensource.org/licenses/MIT MIT
*/
namespace Madapaja\TwigModule\Resource\Page;
namespace Madapaja\TwigModule;

use BEAR\Resource\RenderInterface;
use Madapaja\TwigModule\TwigAppMetaTestModule;
use Madapaja\TwigModule\TwigRenderer;
use PHPUnit_Framework_TestCase;
use Ray\Di\Injector;

class AppMetaTest extends PHPUnit_Framework_TestCase
{
public function testRenderer()
{
/** @var $renderer TwigRenderer */
/** @var TwigRenderer $renderer */
$renderer = (new Injector(new TwigAppMetaTestModule()))->getInstance(RenderInterface::class);
$this->assertInstanceOf(TwigRenderer::class, $renderer);
$this->assertFalse($renderer->twig->isDebug());
Expand Down
7 changes: 5 additions & 2 deletions tests/AppPathProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ public function testAppPathProvider()
}
}

/** @var $renderer TwigRenderer */
/** @var TwigRenderer $renderer */
$renderer = (new Injector(new AppPathProviderTestModule($appDir)))->getInstance(TwigRenderer::class);
$this->assertSame($paths, $renderer->twig->getLoader()->getPaths());
/** @var \Twig_Loader_Filesystem $loader */
$loader = $renderer->twig->getLoader();
$this->assertInstanceOf(\Twig_Loader_Filesystem::class, $loader);
$this->assertSame($paths, $loader->getPaths());
}
}
7 changes: 4 additions & 3 deletions tests/ArrayLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
*
* @license http://opensource.org/licenses/MIT MIT
*/
namespace Madapaja\TwigModule\Resource\Page;
namespace Madapaja\TwigModule;

use Madapaja\TwigModule\TwigArrayLoaderTestModule;
use Madapaja\TwigModule\TwigRenderer;
use Madapaja\TwigModule\Resource\Page\Index;
use Madapaja\TwigModule\Resource\Page\NoTemplate;
use Madapaja\TwigModule\Resource\Page\Page;
use PHPUnit_Framework_TestCase;
use Ray\Di\Injector;

Expand Down
4 changes: 2 additions & 2 deletions tests/ExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*
* @license http://opensource.org/licenses/MIT MIT
*/
namespace Madapaja\TwigModule\Resource\Page;
namespace Madapaja\TwigModule;

use Madapaja\TwigModule\TwigExtensionTestModule;
use Madapaja\TwigModule\Resource\Page\TwigFilter;
use PHPUnit_Framework_TestCase;
use Ray\Di\Injector;

Expand Down
2 changes: 2 additions & 0 deletions tests/Fake/src/Resource/Page/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

class Index extends ResourceObject
{
public $templatePath;

public function onGet($name = 'BEAR.Sunday')
{
$this['name'] = $name;
Expand Down
12 changes: 6 additions & 6 deletions tests/FileLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
*
* @license http://opensource.org/licenses/MIT MIT
*/
namespace Madapaja\TwigModule\Resource\Page;
namespace Madapaja\TwigModule;

use BEAR\Resource\Code;
use Madapaja\TwigModule\TwigAppMetaTestModule;
use Madapaja\TwigModule\TwigFileLoaderTestModule;
use Madapaja\TwigModule\TwigRenderer;
use Madapaja\TwigModule\Resource\Page\Index;
use Madapaja\TwigModule\Resource\Page\NoTemplate;
use Madapaja\TwigModule\Resource\Page\Page;
use PHPUnit_Framework_TestCase;
use Ray\Di\Injector;

Expand All @@ -32,11 +32,11 @@ public function testRenderer()

public function testTwigOptions()
{
/** @var $renderer TwigRenderer */
/** @var TwigRenderer $renderer */
$renderer = (new Injector(new TwigFileLoaderTestModule([$_ENV['TEST_DIR'] . '/Fake/src/Resource'], ['debug' => true])))->getInstance(TwigRenderer::class);
$this->assertTrue($renderer->twig->isDebug());

/** @var $renderer TwigRenderer */
/** @var TwigRenderer $renderer */
$renderer = (new Injector(new TwigFileLoaderTestModule([$_ENV['TEST_DIR'] . '/Fake/src/Resource'], ['debug' => false])))->getInstance(TwigRenderer::class);
$this->assertFalse($renderer->twig->isDebug());
}
Expand Down
4 changes: 2 additions & 2 deletions tests/MobileTemplateFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function testMobileTemplate()
$iphone = 'Mozilla/5.0 (iPhone; CPU iPhone OS 6_0_1 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A523 Safari/8536.25';
$paths = [$_ENV['TEST_DIR'] . '/Fake/src/Resource'];
$templateFinder = new MobileTemplateFinder($iphone, $paths);
$file = $templateFinder->__invoke($_ENV['TEST_DIR'] . '/Resource/Page/Index.php', $iphone);
$file = ($templateFinder)($_ENV['TEST_DIR'] . '/Resource/Page/Index.php');
$expected = 'Page/Index.mobile.twig';
$this->assertSame($expected, $file);
}
Expand All @@ -35,7 +35,7 @@ public function testPcTemplate()
$pc = 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)';
$paths = [$_ENV['TEST_DIR'] . '/Fake/src/Resource'];
$templateFinder = new MobileTemplateFinder($pc, $paths);
$file = $templateFinder->__invoke($_ENV['TEST_DIR'] . '/Resource/Page/Index.php', $pc);
$file = ($templateFinder)($_ENV['TEST_DIR'] . '/Resource/Page/Index.php');
$expected = 'Page/Index.html.twig';
$this->assertSame($expected, $file);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/OptionProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function setUp()

public function testOptionProvider()
{
/** @var $renderer TwigRenderer */
/** @var TwigRenderer $renderer */
$renderer = (new Injector(new OptionProviderTestModule($this->tmpDir, true)))->getInstance(TwigRenderer::class);

$this->assertSame($this->tmpDir . '/twig', $renderer->twig->getCache());
Expand All @@ -32,7 +32,7 @@ public function testOptionProvider()

public function testOptionProviderDebugFalse()
{
/** @var $renderer TwigRenderer */
/** @var TwigRenderer $renderer */
$renderer = (new Injector(new OptionProviderTestModule($this->tmpDir, false)))->getInstance(TwigRenderer::class);
$this->assertFalse($renderer->twig->isDebug());
}
Expand Down
5 changes: 2 additions & 3 deletions tests/WeavedResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
*
* @license http://opensource.org/licenses/MIT MIT
*/
namespace Madapaja\TwigModule\Resource\Page;
namespace Madapaja\TwigModule;

use Madapaja\TwigModule\TwigRenderer;
use Madapaja\TwigModule\TwigWeavedResourceTestModule;
use Madapaja\TwigModule\Resource\Page\Index;
use PHPUnit_Framework_TestCase;
use Ray\Di\Injector;

Expand Down

0 comments on commit 90aed38

Please sign in to comment.