Skip to content

Commit

Permalink
strict_types=1 (#2)
Browse files Browse the repository at this point in the history
* strict_types=1
* Update deps
  • Loading branch information
SmetDenis committed Apr 21, 2021
1 parent 89666b7 commit a46d5b8
Show file tree
Hide file tree
Showing 37 changed files with 141 additions and 47 deletions.
11 changes: 10 additions & 1 deletion .gitattributes
Expand Up @@ -11,5 +11,14 @@
# @link https://github.com/JBZoo/Assets
#

* text eol=lf
/.phan export-ignore
/build export-ignore
/tests export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/phpunit.xml.dist export-ignore
/Makefile export-ignore

* text eol=lf
8 changes: 7 additions & 1 deletion .phan/config.php
Expand Up @@ -13,9 +13,11 @@
* @link https://github.com/JBZoo/Assets
*/

declare(strict_types=1);

$default = include __DIR__ . '/../vendor/jbzoo/codestyle/src/phan/default.php';

return array_merge($default, [
$config = array_merge($default, [
'directory_list' => [
'src',

Expand All @@ -25,3 +27,7 @@
'vendor/jbzoo/less',
]
]);

$config['plugins'][] = 'NotFullyQualifiedUsagePlugin';

return $config;
8 changes: 8 additions & 0 deletions .travis.yml
Expand Up @@ -19,6 +19,14 @@ php:
- 7.2
- 7.3
- 7.4
- 8.0
- nightly

jobs:
fast_finish: true
allow_failures:
- php: 8.0
- php: nightly

env:
matrix:
Expand Down
2 changes: 1 addition & 1 deletion README.md
@@ -1,6 +1,6 @@
# JBZoo / Assets

[![Build Status](https://travis-ci.org/JBZoo/Assets.svg)](https://travis-ci.org/JBZoo/Assets) [![Coverage Status](https://coveralls.io/repos/JBZoo/Assets/badge.svg)](https://coveralls.io/github/JBZoo/Assets) [![Psalm Coverage](https://shepherd.dev/github/JBZoo/Assets/coverage.svg)](https://shepherd.dev/github/JBZoo/Assets)
[![Build Status](https://travis-ci.org/JBZoo/Assets.svg)](https://travis-ci.org/JBZoo/Assets) [![Coverage Status](https://coveralls.io/repos/JBZoo/Assets/badge.svg)](https://coveralls.io/github/JBZoo/Assets) [![Psalm Coverage](https://shepherd.dev/github/JBZoo/Assets/coverage.svg)](https://shepherd.dev/github/JBZoo/Assets) [![PHP Strict Types](https://img.shields.io/badge/strict__types-%3D1-brightgreen)](https://www.php.net/manual/en/language.types.declarations.php#language.types.declarations.strict)
[![Stable Version](https://poser.pugx.org/jbzoo/assets/version)](https://packagist.org/packages/jbzoo/assets) [![Latest Unstable Version](https://poser.pugx.org/jbzoo/assets/v/unstable)](https://packagist.org/packages/jbzoo/assets) [![Dependents](https://poser.pugx.org/jbzoo/assets/dependents)](https://packagist.org/packages/jbzoo/assets/dependents?order_by=downloads) [![GitHub Issues](https://img.shields.io/github/issues/jbzoo/assets)](https://github.com/JBZoo/Assets/issues) [![Total Downloads](https://poser.pugx.org/jbzoo/assets/downloads)](https://packagist.org/packages/jbzoo/assets/stats) [![GitHub License](https://img.shields.io/github/license/jbzoo/assets)](https://github.com/JBZoo/Assets/blob/master/LICENSE)


Expand Down
10 changes: 5 additions & 5 deletions composer.json
Expand Up @@ -19,14 +19,14 @@
"require" : {
"php" : ">=7.2",

"jbzoo/utils" : "^4.2.3",
"jbzoo/path" : "^3.0.3",
"jbzoo/less" : "^4.0.4",
"jbzoo/data" : "^4.1.3"
"jbzoo/utils" : "^4.3.0",
"jbzoo/path" : "^3.1.0",
"jbzoo/less" : "^4.1.0",
"jbzoo/data" : "^4.2.0"
},

"require-dev" : {
"jbzoo/toolbox-dev" : "^2.6.2",
"jbzoo/toolbox-dev" : "^2.10.0",
"symfony/filesystem" : "^5.2.3"
},

Expand Down
4 changes: 3 additions & 1 deletion src/Asset/AbstractAsset.php
Expand Up @@ -13,6 +13,8 @@
* @link https://github.com/JBZoo/Assets
*/

declare(strict_types=1);

namespace JBZoo\Assets\Asset;

use JBZoo\Assets\Manager;
Expand Down Expand Up @@ -120,5 +122,5 @@ public function getOptions(): Data
/**
* @return array
*/
abstract public function load();
abstract public function load(): array;
}
6 changes: 4 additions & 2 deletions src/Asset/AbstractFile.php
Expand Up @@ -13,6 +13,8 @@
* @link https://github.com/JBZoo/Assets
*/

declare(strict_types=1);

namespace JBZoo\Assets\Asset;

use JBZoo\Assets\Exception;
Expand All @@ -29,7 +31,7 @@ abstract class AbstractFile extends AbstractAsset
/**
* @inheritDoc
*/
public function load()
public function load(): array
{
return [static::TYPE, $this->findSource()];
}
Expand All @@ -43,7 +45,7 @@ public function load()
*/
protected function findSource(): ?string
{
if (!is_string($this->source)) {
if (!\is_string($this->source)) {
throw new Exception('Source must be string type');
}

Expand Down
8 changes: 5 additions & 3 deletions src/Asset/Callback.php
Expand Up @@ -13,13 +13,15 @@
* @link https://github.com/JBZoo/Assets
*/

declare(strict_types=1);

namespace JBZoo\Assets\Asset;

/**
* Class Callback
* @package JBZoo\Assets\Asset
*/
class Callback extends AbstractAsset
final class Callback extends AbstractAsset
{
/**
* @var callable
Expand All @@ -29,9 +31,9 @@ class Callback extends AbstractAsset
/**
* @inheritDoc
*/
public function load()
public function load(): array
{
$result = call_user_func($this->source, $this);
$result = \call_user_func($this->source, $this);

return [AbstractAsset::TYPE_CALLBACK, $result];
}
Expand Down
8 changes: 5 additions & 3 deletions src/Asset/Collection.php
Expand Up @@ -13,6 +13,8 @@
* @link https://github.com/JBZoo/Assets
*/

declare(strict_types=1);

namespace JBZoo\Assets\Asset;

use JBZoo\Assets\Exception;
Expand All @@ -21,17 +23,17 @@
* Class Collection
* @package JBZoo\Assets\Asset
*/
class Collection extends AbstractAsset
final class Collection extends AbstractAsset
{
/**
* @return array
*/
public function load()
public function load(): array
{
$factory = $this->eManager->getFactory();

$result = [];
if (is_array($this->source)) {
if (\is_array($this->source)) {
foreach ($this->source as $key => $source) {
$subAlias = $this->alias . '-' . $key;
$asset = $factory->create($subAlias, $source, $this->dependencies, $this->options);
Expand Down
12 changes: 7 additions & 5 deletions src/Asset/CssCode.php
Expand Up @@ -13,6 +13,8 @@
* @link https://github.com/JBZoo/Assets
*/

declare(strict_types=1);

namespace JBZoo\Assets\Asset;

use JBZoo\Assets\Exception;
Expand All @@ -21,7 +23,7 @@
* Class CssCode
* @package JBZoo\Assets\Asset
*/
class CssCode extends AbstractAsset
final class CssCode extends AbstractAsset
{
/**
* @var string
Expand All @@ -31,15 +33,15 @@ class CssCode extends AbstractAsset
/**
* @inheritDoc
*/
public function load()
public function load(): array
{
if (!is_string($this->source)) {
if (!\is_string($this->source)) {
throw new Exception('Source must be string type');
}

$source = trim($this->source);
$source = \trim($this->source);

if ((stripos($source, '<style') === 0) && preg_match('#<style.*?>(.*?)</style>#ius', $source, $matches)) {
if ((\stripos($source, '<style') === 0) && \preg_match('#<style.*?>(.*?)</style>#ius', $source, $matches)) {
$source = $matches[1];
}

Expand Down
4 changes: 3 additions & 1 deletion src/Asset/CssFile.php
Expand Up @@ -13,13 +13,15 @@
* @link https://github.com/JBZoo/Assets
*/

declare(strict_types=1);

namespace JBZoo\Assets\Asset;

/**
* Class CssFile
* @package JBZoo\Assets\Asset
*/
class CssFile extends AbstractFile
final class CssFile extends AbstractFile
{
public const TYPE = AbstractAsset::TYPE_CSS_FILE;
}
10 changes: 6 additions & 4 deletions src/Asset/JsCode.php
Expand Up @@ -13,6 +13,8 @@
* @link https://github.com/JBZoo/Assets
*/

declare(strict_types=1);

namespace JBZoo\Assets\Asset;

use JBZoo\Assets\Exception;
Expand All @@ -31,15 +33,15 @@ class JsCode extends AbstractFile
/**
* @inheritDoc
*/
public function load()
public function load(): array
{
if (!is_string($this->source)) {
if (!\is_string($this->source)) {
throw new Exception('Source must be string type');
}

$source = trim($this->source);
$source = \trim($this->source);

if ((stripos($source, '<script') === 0) && preg_match('#<script.*?>(.*?)</script>#ius', $source, $matches)) {
if ((\stripos($source, '<script') === 0) && \preg_match('#<script.*?>(.*?)</script>#ius', $source, $matches)) {
$source = $matches[1];
}

Expand Down
4 changes: 3 additions & 1 deletion src/Asset/JsFile.php
Expand Up @@ -13,13 +13,15 @@
* @link https://github.com/JBZoo/Assets
*/

declare(strict_types=1);

namespace JBZoo\Assets\Asset;

/**
* Class JsFile
* @package JBZoo\Assets\Asset
*/
class JsFile extends AbstractFile
final class JsFile extends AbstractFile
{
public const TYPE = AbstractAsset::TYPE_JS_FILE;
}
4 changes: 3 additions & 1 deletion src/Asset/JsxCode.php
Expand Up @@ -13,13 +13,15 @@
* @link https://github.com/JBZoo/Assets
*/

declare(strict_types=1);

namespace JBZoo\Assets\Asset;

/**
* Class JsxCode
* @package JBZoo\Assets\Asset
*/
class JsxCode extends JsCode
final class JsxCode extends JsCode
{
/**
* @var string
Expand Down
4 changes: 3 additions & 1 deletion src/Asset/JsxFile.php
Expand Up @@ -13,13 +13,15 @@
* @link https://github.com/JBZoo/Assets
*/

declare(strict_types=1);

namespace JBZoo\Assets\Asset;

/**
* Class JsxFile
* @package JBZoo\Assets\Asset
*/
class JsxFile extends AbstractFile
final class JsxFile extends AbstractFile
{
public const TYPE = AbstractAsset::TYPE_JSX_FILE;
}
6 changes: 4 additions & 2 deletions src/Asset/LessFile.php
Expand Up @@ -13,6 +13,8 @@
* @link https://github.com/JBZoo/Assets
*/

declare(strict_types=1);

namespace JBZoo\Assets\Asset;

use JBZoo\Less\Less;
Expand All @@ -21,14 +23,14 @@
* Class LessFile
* @package JBZoo\Assets\Asset
*/
class LessFile extends AbstractFile
final class LessFile extends AbstractFile
{
public const TYPE = AbstractAsset::TYPE_LESS_FILE;

/**
* @inheritDoc
*/
public function load()
public function load(): array
{
$result = parent::load();
$compiled = null;
Expand Down
8 changes: 5 additions & 3 deletions src/Collection.php
Expand Up @@ -13,6 +13,8 @@
* @link https://github.com/JBZoo/Assets
*/

declare(strict_types=1);

namespace JBZoo\Assets;

use Countable;
Expand All @@ -23,7 +25,7 @@
*
* @package JBZoo\Assets
*/
class Collection implements Countable
final class Collection implements Countable
{
/**
* Holds registered assets.
Expand Down Expand Up @@ -85,7 +87,7 @@ public function remove($name): void

/** @noinspection SuspiciousLoopInspection */
foreach ($names as $name) {
if (array_key_exists($name, $this->assets)) {
if (\array_key_exists($name, $this->assets)) {
unset($this->assets[$name]);
}
}
Expand All @@ -98,6 +100,6 @@ public function remove($name): void
*/
public function count(): int
{
return count($this->assets);
return \count($this->assets);
}
}
2 changes: 2 additions & 0 deletions src/Exception.php
Expand Up @@ -13,6 +13,8 @@
* @link https://github.com/JBZoo/Assets
*/

declare(strict_types=1);

namespace JBZoo\Assets;

/**
Expand Down

0 comments on commit a46d5b8

Please sign in to comment.