Skip to content

Commit

Permalink
code style
Browse files Browse the repository at this point in the history
  • Loading branch information
Gappa committed Sep 4, 2018
1 parent 0a008f8 commit 5759bbd
Show file tree
Hide file tree
Showing 18 changed files with 62 additions and 102 deletions.
8 changes: 4 additions & 4 deletions WebLoader/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Compiler
private $absoluteUrl = false;


public function __construct(IFileCollection $files, IOutputNamingConvention $convention, $outputDir)
public function __construct(IFileCollection $files, IOutputNamingConvention $convention, string $outputDir)
{
$this->collection = $files;
$this->namingConvention = $convention;
Expand Down Expand Up @@ -135,7 +135,7 @@ public function getJoinFiles(): bool
*/
public function setJoinFiles(bool $joinFiles): void
{
$this->joinFiles = (bool) $joinFiles;
$this->joinFiles = $joinFiles;
}


Expand All @@ -147,7 +147,7 @@ public function isAsync(): bool

public function setAsync(bool $async): self
{
$this->async = (bool) $async;
$this->async = $async;
return $this;
}

Expand Down Expand Up @@ -183,7 +183,7 @@ public function setAbsoluteUrl(bool $absoluteUrl): self
*/
public function setCheckLastModified(bool $checkLastModified): void
{
$this->checkLastModified = (bool) $checkLastModified;
$this->checkLastModified = $checkLastModified;
}


Expand Down
10 changes: 4 additions & 6 deletions WebLoader/FileCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ public function getFiles(): array
/**
* Make path absolute
*
* @param $path string
* @throws \WebLoader\FileNotFoundException
*/
public function cannonicalizePath($path): string
public function cannonicalizePath(string $path): string
{
$rel = Path::normalize($this->root . '/' . $path);
if (file_exists($rel)) {
Expand All @@ -67,7 +66,7 @@ public function cannonicalizePath($path): string

/**
* Add file
* @param $file string filename
* @param string|\SplFileInfo
*/
public function addFile($file): void
{
Expand Down Expand Up @@ -97,7 +96,7 @@ public function addFiles($files): void
* Remove file
* @param $file string filename
*/
public function removeFile($file): void
public function removeFile(string $file): void
{
$this->removeFiles([$file]);
}
Expand Down Expand Up @@ -165,9 +164,8 @@ public function getRoot(): string

/**
* Add watch file
* @param $file string filename
*/
public function addWatchFile($file): void
public function addWatchFile(string $file): void
{
$file = $this->cannonicalizePath((string) $file);

Expand Down
2 changes: 1 addition & 1 deletion WebLoader/IOutputNamingConvention.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
*/
interface IOutputNamingConvention
{
public function getFilename(array $files, Compiler $compiler);
public function getFilename(array $files, Compiler $compiler): string;
}
35 changes: 0 additions & 35 deletions WebLoader/Nette/CssLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,93 +28,58 @@ class CssLoader extends \WebLoader\Nette\WebLoader
private $alternate = false;


/**
* Get media
*/
public function getMedia(): string
{
return $this->media;
}


/**
* Get type
*/
public function getType(): string
{
return $this->type;
}


/**
* Get title
*/
public function getTitle(): string
{
return $this->title;
}


/**
* Is alternate ?
*/
public function isAlternate(): bool
{
return $this->alternate;
}


/**
* Set media
*
* @return \WebLoader\Nette\CssLoader
*/
public function setMedia(string $media): self
{
$this->media = $media;
return $this;
}


/**
* Set type
*
* @return \WebLoader\Nette\CssLoader
*/
public function setType(string $type): self
{
$this->type = $type;
return $this;
}


/**
* Set title
*
* @return \WebLoader\Nette\CssLoader
*/
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}


/**
* Set alternate
*
* @return \WebLoader\Nette\CssLoader
*/
public function setAlternate(bool $alternate): self
{
$this->alternate = $alternate;
return $this;
}


/**
* Get link element
*/
public function getElement(string $source): Html
{
if ($this->alternate) {
Expand Down
2 changes: 1 addition & 1 deletion WebLoader/Nette/CssUrlFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
class CssUrlFilter extends \WebLoader\Filter\CssUrlsFilter
{
public function __construct($docRoot, IRequest $httpRequest)
public function __construct(string $docRoot, IRequest $httpRequest)
{
parent::__construct($docRoot, $httpRequest->getUrl()->getBasePath());
}
Expand Down
2 changes: 1 addition & 1 deletion WebLoader/Nette/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function loadConfiguration(): void
}


private function addWebLoader(ContainerBuilder $builder, $name, $config): void
private function addWebLoader(ContainerBuilder $builder, string $name, array $config): void
{
$filesServiceName = $this->prefix($name . 'Files');

Expand Down
4 changes: 2 additions & 2 deletions WebLoader/Nette/WebLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ abstract class WebLoader extends \Nette\Application\UI\Control
private $appendLastModified;


public function __construct(Compiler $compiler, $tempPath, $appendLastModified)
public function __construct(Compiler $compiler, string $tempPath, bool $appendLastModified)
{
parent::__construct();
$this->compiler = $compiler;
Expand Down Expand Up @@ -95,7 +95,7 @@ public function render(): void
}


protected function getGeneratedFilePath($file)
protected function getGeneratedFilePath(string $file)
{
$path = $this->tempPath . '/' . $file->file;

Expand Down
2 changes: 1 addition & 1 deletion WebLoader/Path.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class Path
{
public static function normalize($path)
public static function normalize(string $path): string
{
$path = strtr($path, '\\', '/');
$root = (strpos($path, '/') === 0) ? '/' : '';
Expand Down
27 changes: 12 additions & 15 deletions tests/CompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CompilerTest extends TestCase
private $object;


protected function setUp()
protected function setUp(): void
{
$fileCollection = Mockery::mock('WebLoader\IFileCollection');
$fileCollection->shouldReceive('getFiles')->andReturn([
Expand All @@ -46,16 +46,13 @@ protected function setUp()
}


/**
* @return array
*/
private function getTempFiles()
private function getTempFiles(): array
{
return glob(__DIR__ . '/temp/webloader-*');
}


public function testJoinFiles()
public function testJoinFiles(): void
{
$this->assertTrue($this->object->getJoinFiles());

Expand All @@ -65,7 +62,7 @@ public function testJoinFiles()
}


public function testEmptyFiles()
public function testEmptyFiles(): void
{
$this->assertTrue($this->object->getJoinFiles());
$this->object->setFileCollection(new \WebLoader\FileCollection());
Expand All @@ -76,7 +73,7 @@ public function testEmptyFiles()
}


public function testNotJoinFiles()
public function testNotJoinFiles(): void
{
$this->object->setJoinFiles(false);
$this->assertFalse($this->object->getJoinFiles());
Expand All @@ -90,13 +87,13 @@ public function testNotJoinFiles()
/**
* @expectedException \WebLoader\FileNotFoundException
*/
public function testSetOutDir()
public function testSetOutDir(): void
{
$this->object->setOutputDir('blablabla');
}


public function testGeneratingAndFilters()
public function testGeneratingAndFilters(): void
{
$this->object->addFileFilter(function ($code) {
return strrev($code);
Expand Down Expand Up @@ -124,7 +121,7 @@ public function testGeneratingAndFilters()
}


public function testGenerateReturnsSourceFilePaths()
public function testGenerateReturnsSourceFilePaths(): void
{
$res = $this->object->generate();
$this->assertInternalType('array', $res[0]->sourceFiles);
Expand All @@ -133,7 +130,7 @@ public function testGenerateReturnsSourceFilePaths()
}


public function testFilters()
public function testFilters(): void
{
$filter = function ($code, \WebLoader\Compiler $loader) {
return $code . $code;
Expand All @@ -144,7 +141,7 @@ public function testFilters()
}


public function testFileFilters()
public function testFileFilters(): void
{
$filter = function ($code, \WebLoader\Compiler $loader, $file = null) {
return $code . $code;
Expand All @@ -158,7 +155,7 @@ public function testFileFilters()
/**
* @expectedException \TypeError
*/
public function testNonCallableFilter()
public function testNonCallableFilter(): void
{
$this->object->addFilter(4);
}
Expand All @@ -167,7 +164,7 @@ public function testNonCallableFilter()
/**
* @expectedException \TypeError
*/
public function testNonCallableFileFilter()
public function testNonCallableFileFilter(): void
{
$this->object->addFileFilter(4);
}
Expand Down
10 changes: 5 additions & 5 deletions tests/DefaultOutputNamingConventionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ class DefaultOutputNamingConventionTest extends TestCase
private $compiler;


protected function setUp()
protected function setUp(): void
{
$this->object = new DefaultOutputNamingConvention();
$this->compiler = \Mockery::mock('Webloader\Compiler');
}


public function testMultipleFiles()
public function testMultipleFiles(): void
{
$files = [
__DIR__ . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'a.txt',
Expand All @@ -44,7 +44,7 @@ public function testMultipleFiles()
}


public function testOneFile()
public function testOneFile(): void
{
$files = [
__DIR__ . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'a.txt',
Expand All @@ -55,7 +55,7 @@ public function testOneFile()
}


public function testCssConvention()
public function testCssConvention(): void
{
$files = [
__DIR__ . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'a.txt',
Expand All @@ -66,7 +66,7 @@ public function testCssConvention()
}


public function testJsConvention()
public function testJsConvention(): void
{
$files = [
__DIR__ . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'a.txt',
Expand Down
4 changes: 2 additions & 2 deletions tests/FileCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ class FileCollectionTest extends TestCase
private $object;


protected function setUp()
protected function setUp(): void
{
$this->object = new FileCollection(__DIR__ . '/fixtures');
}


public function testAddGetFiles()
public function testAddGetFiles(): void
{
$this->object->addFile('a.txt');
$this->object->addFile(__DIR__ . '/fixtures/a.txt');
Expand Down
Loading

0 comments on commit 5759bbd

Please sign in to comment.