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

Reduce composer bundle size #2

Merged
merged 2 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
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
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.yml]
indent_size = 2
10 changes: 10 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
* text=auto
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
/.github export-ignore
/.php-cs-fixer.dist.php export-ignore
/docker export-ignore
/phpstan.neon.dist export-ignore
/phpunit.xml.dist export-ignore
/tests export-ignore
22 changes: 11 additions & 11 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
return (new Config())
->setFinder(PhpCsFixer\Finder::create()->in(__DIR__ . '/src'))
->setRules([
'line_ending' => false,
'concat_space' => [
'spacing' => 'one',
],
'cast_spaces' => [
'space' => 'none',
],
'not_operator_with_successor_space' => false,
'simplified_null_return' => false,
'explicit_string_variable' => true,
'phpdoc_to_comment' => false,
'line_ending' => false,
'concat_space' => [
'spacing' => 'one',
],
'cast_spaces' => [
'space' => 'none',
],
'not_operator_with_successor_space' => false,
'simplified_null_return' => false,
'explicit_string_variable' => true,
'phpdoc_to_comment' => false,
])
->setRiskyAllowed(true);
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ Package which helps you to delay (sleep) your code for some time.
## Installation

### Requirements

- Laravel 8.12+, 9.0+, 10.0+
- PHP 8.0

### Installation

Require the package via Composer:

```bash
Expand Down Expand Up @@ -137,6 +139,7 @@ $this->delay()
We'll appreciate your collaboration to this package.

When making pull requests, make sure:

* All tests are passing: `composer test`
* Test coverage is not reduced: `composer test-coverage`
* There are no PHPStan errors: `composer phpstan`
Expand Down
114 changes: 57 additions & 57 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
{
"name": "newman/laravel-delay",
"description": "Laravel delay helper package",
"keywords": [
"delay",
"sleep",
"timeout"
],
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Edgars Neimanis",
"email": "[email protected]"
}
],
"require": {
"php": "^8.0",
"illuminate/contracts": "^8.12|^9.0|^10.0",
"illuminate/support": "^8.12|^9.0|^10.0",
"nesbot/carbon": "^2.13"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
"nunomaduro/larastan": "^1.0|^2.4",
"orchestra/testbench": "^6.0|^7.0|^8.0",
"phpunit/phpunit": "^8.0|^9.0"
},
"autoload": {
"psr-4": {
"Newman\\LaravelDelay\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Newman\\LaravelDelay\\Tests\\": "tests/"
}
},
"scripts": {
"phpstan": "phpstan analyse --memory-limit=256M",
"lint": "php-cs-fixer fix --diff --dry-run",
"fix-style": "php-cs-fixer fix",
"test": "./vendor/bin/phpunit --colors=always --verbose",
"test-coverage": "php -dpcov.enabled=1 -dpcov.directory=src/ -dpcov.exclude=\"~vendor~\" ./vendor/bin/phpunit --colors=always --verbose --coverage-text",
"test-coverage-html": "php -dpcov.enabled=1 -dpcov.directory=src/ -dpcov.exclude=\"~vendor~\" ./vendor/bin/phpunit --colors=always --verbose --coverage-html phpunit-coverage"
},
"extra": {
"laravel": {
"providers": [
"Newman\\LaravelDelay\\DelayServiceProvider"
]
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"sort-packages": true
}
"name": "newman/laravel-delay",
"description": "Laravel delay helper package",
"keywords": [
"delay",
"sleep",
"timeout"
],
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Edgars Neimanis",
"email": "[email protected]"
}
],
"require": {
"php": "^8.0",
"illuminate/contracts": "^8.12|^9.0|^10.0",
"illuminate/support": "^8.12|^9.0|^10.0",
"nesbot/carbon": "^2.13"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
"nunomaduro/larastan": "^1.0|^2.4",
"orchestra/testbench": "^6.0|^7.0|^8.0",
"phpunit/phpunit": "^8.0|^9.0"
},
"autoload": {
"psr-4": {
"Newman\\LaravelDelay\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Newman\\LaravelDelay\\Tests\\": "tests/"
}
},
"scripts": {
"phpstan": "phpstan analyse --memory-limit=256M",
"lint": "php-cs-fixer fix --diff --dry-run",
"fix-style": "php-cs-fixer fix",
"test": "./vendor/bin/phpunit --colors=always --verbose",
"test-coverage": "php -dpcov.enabled=1 -dpcov.directory=src/ -dpcov.exclude=\"~vendor~\" ./vendor/bin/phpunit --colors=always --verbose --coverage-text",
"test-coverage-html": "php -dpcov.enabled=1 -dpcov.directory=src/ -dpcov.exclude=\"~vendor~\" ./vendor/bin/phpunit --colors=always --verbose --coverage-html phpunit-coverage"
},
"extra": {
"laravel": {
"providers": [
"Newman\\LaravelDelay\\DelayServiceProvider"
]
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"sort-packages": true
}
}
14 changes: 7 additions & 7 deletions src/Delay.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class Delay extends DelayAbstract implements DelayContract
*/
protected function goToSleep(): void
{
if (!empty($this->forMicroseconds)) {
usleep($this->forMicroseconds);
} else if (!empty($this->forMiliseconds)) {
usleep($this->forMiliseconds * 1000);
} else if (!empty($this->forSeconds)) {
sleep($this->forSeconds);
}
if (!empty($this->forMicroseconds)) {
usleep($this->forMicroseconds);
} else if (!empty($this->forMiliseconds)) {
usleep($this->forMiliseconds * 1000);
} else if (!empty($this->forSeconds)) {
sleep($this->forSeconds);
}
}
}
70 changes: 35 additions & 35 deletions src/DelayAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public function __construct(protected Application $app)
*/
public function forSeconds(int $seconds): static
{
$this->forSeconds = $seconds;
$this->forSeconds = $seconds;

return $this;
return $this;
}

/**
Expand All @@ -83,9 +83,9 @@ public function forSeconds(int $seconds): static
*/
public function forMiliseconds(int $miliseconds): static
{
$this->forMiliseconds = $miliseconds;
$this->forMiliseconds = $miliseconds;

return $this;
return $this;
}

/**
Expand All @@ -96,9 +96,9 @@ public function forMiliseconds(int $miliseconds): static
*/
public function forMicroseconds(int $microseconds): static
{
$this->forMicroseconds = $microseconds;
$this->forMicroseconds = $microseconds;

return $this;
return $this;
}

/**
Expand All @@ -109,7 +109,7 @@ public function forMicroseconds(int $microseconds): static
*/
public function for(int $seconds): static
{
return $this->forSeconds($seconds);
return $this->forSeconds($seconds);
}

/**
Expand All @@ -120,7 +120,7 @@ public function for(int $seconds): static
*/
public function forMs(int $miliseconds): static
{
return $this->forMiliseconds($miliseconds);
return $this->forMiliseconds($miliseconds);
}

/**
Expand All @@ -131,9 +131,9 @@ public function forMs(int $miliseconds): static
*/
public function till(CarbonInterface $carbon): static
{
$this->forSeconds = $carbon->diffInSeconds();
$this->forSeconds = $carbon->diffInSeconds();

return $this;
return $this;
}

/**
Expand All @@ -144,9 +144,9 @@ public function till(CarbonInterface $carbon): static
*/
public function environments(array $environments): static
{
$this->environments = $environments;
$this->environments = $environments;

return $this;
return $this;
}

/**
Expand All @@ -157,9 +157,9 @@ public function environments(array $environments): static
*/
public function except(array $environments): static
{
$this->exceptedEnvironments = $environments;
$this->exceptedEnvironments = $environments;

return $this;
return $this;
}

/**
Expand All @@ -170,9 +170,9 @@ public function except(array $environments): static
*/
public function exceptWhen(Closure $callback): static
{
$this->exceptCallbacks[] = $callback;
$this->exceptCallbacks[] = $callback;

return $this;
return $this;
}

/**
Expand All @@ -183,7 +183,7 @@ public function exceptWhen(Closure $callback): static
*/
protected function getEnvironment(): string
{
return (string)$this->app->environment();
return (string)$this->app->environment();
}

/**
Expand All @@ -193,35 +193,35 @@ protected function getEnvironment(): string
*/
protected function _shouldSleep(): bool
{
$allowedEnvironments = $this->environments ?? [];
$allowedEnvironments = $this->environments ?? [];

if (!empty($this->exceptedEnvironments)) {
$allowedEnvironments = array_filter($allowedEnvironments, fn($env) => in_array($env, $this->exceptedEnvironments));
}
if (!empty($this->exceptedEnvironments)) {
$allowedEnvironments = array_filter($allowedEnvironments, fn($env) => in_array($env, $this->exceptedEnvironments));
}

if (!empty($allowedEnvironments) && !in_array($this->getEnvironment(), $allowedEnvironments)) {
return false;
} else if (!empty($this->exceptedEnvironments) && in_array($this->getEnvironment(), $this->exceptedEnvironments)) {
return false;
}
if (!empty($allowedEnvironments) && !in_array($this->getEnvironment(), $allowedEnvironments)) {
return false;
} else if (!empty($this->exceptedEnvironments) && in_array($this->getEnvironment(), $this->exceptedEnvironments)) {
return false;
}

foreach ($this->exceptCallbacks as $callback) {
if ($callback()) {
return false;
}
}
foreach ($this->exceptCallbacks as $callback) {
if ($callback()) {
return false;
}
}

return true;
return true;
}

/**
* Destruct object.
*/
public function __destruct()
{
if ($this->_shouldSleep()) {
$this->goToSleep();
}
if ($this->_shouldSleep()) {
$this->goToSleep();
}
}

/**
Expand Down
Loading