Skip to content

Commit

Permalink
Merge pull request #72 from mjerwin/array-helpers
Browse files Browse the repository at this point in the history
Replace array_* with Arr::* for 5.8 support
  • Loading branch information
mpociot authored Feb 27, 2019
2 parents 83239c2 + 38bcb4e commit cc347c1
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 19 deletions.
3 changes: 2 additions & 1 deletion src/Checks/ComposerWithDevDependenciesIsUpToDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace BeyondCode\SelfDiagnosis\Checks;

use BeyondCode\SelfDiagnosis\Composer;
use Illuminate\Support\Arr;

class ComposerWithDevDependenciesIsUpToDate implements Check
{
Expand Down Expand Up @@ -37,7 +38,7 @@ public function name(array $config): string
*/
public function check(array $config): bool
{
$additionalOptions = array_get($config, 'additional_options', '');
$additionalOptions = Arr::get($config, 'additional_options', '');

$this->output = $this->composer->installDryRun($additionalOptions);

Expand Down
3 changes: 2 additions & 1 deletion src/Checks/ComposerWithoutDevDependenciesIsUpToDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace BeyondCode\SelfDiagnosis\Checks;

use BeyondCode\SelfDiagnosis\Composer;
use Illuminate\Support\Arr;

class ComposerWithoutDevDependenciesIsUpToDate implements Check
{
Expand Down Expand Up @@ -37,7 +38,7 @@ public function name(array $config): string
*/
public function check(array $config): bool
{
$additionalOptions = array_get($config, 'additional_options', '');
$additionalOptions = Arr::get($config, 'additional_options', '');

$this->output = $this->composer->installDryRun('--no-dev ' . $additionalOptions);

Expand Down
3 changes: 2 additions & 1 deletion src/Checks/CorrectPhpVersionIsInstalled.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Filesystem\Filesystem;
use Composer\Semver\Semver;
use Illuminate\Support\Arr;

class CorrectPhpVersionIsInstalled implements Check
{
Expand Down Expand Up @@ -65,6 +66,6 @@ public function message(array $config): string
public function getRequiredPhpConstraint()
{
$composer = json_decode($this->filesystem->get(base_path('composer.json')), true);
return array_get($composer, 'require.php');
return Arr::get($composer, 'require.php');
}
}
5 changes: 3 additions & 2 deletions src/Checks/DatabaseCanBeAccessed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace BeyondCode\SelfDiagnosis\Checks;

use DB;
use Illuminate\Support\Arr;

class DatabaseCanBeAccessed implements Check
{
Expand All @@ -28,11 +29,11 @@ public function name(array $config): string
public function check(array $config): bool
{
try {
if (array_get($config, 'default_connection', true)) {
if (Arr::get($config, 'default_connection', true)) {
DB::connection()->getPdo();
}

foreach (array_get($config, 'connections', []) as $connection) {
foreach (Arr::get($config, 'connections', []) as $connection) {
DB::connection($connection)->getPdo();
}

Expand Down
3 changes: 2 additions & 1 deletion src/Checks/DirectoriesHaveCorrectPermissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace BeyondCode\SelfDiagnosis\Checks;

use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Filesystem\Filesystem;

Expand Down Expand Up @@ -54,7 +55,7 @@ public function message(array $config): string
*/
public function check(array $config): bool
{
$this->paths = Collection::make(array_get($config, 'directories', []));
$this->paths = Collection::make(Arr::get($config, 'directories', []));

$this->paths = $this->paths->reject(function ($path) {
return $this->filesystem->isWritable($path);
Expand Down
3 changes: 2 additions & 1 deletion src/Checks/LocalesAreInstalled.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace BeyondCode\SelfDiagnosis\Checks;

use BeyondCode\SelfDiagnosis\SystemFunctions;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;

class LocalesAreInstalled implements Check
Expand Down Expand Up @@ -45,7 +46,7 @@ public function name(array $config): string
*/
public function check(array $config): bool
{
$this->missingLocales = new Collection(array_get($config, 'required_locales', []));
$this->missingLocales = new Collection(Arr::get($config, 'required_locales', []));
if ($this->missingLocales->isEmpty()) {
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Checks/PhpExtensionsAreDisabled.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace BeyondCode\SelfDiagnosis\Checks;

use Illuminate\Support\Arr;
use Illuminate\Support\Collection;

class PhpExtensionsAreDisabled implements Check
Expand Down Expand Up @@ -29,7 +30,7 @@ public function name(array $config): string
*/
public function check(array $config): bool
{
$this->extensions = Collection::make(array_get($config, 'extensions', []));
$this->extensions = Collection::make(Arr::get($config, 'extensions', []));
$this->extensions = $this->extensions->reject(function ($ext) {
return extension_loaded($ext) === false;
});
Expand Down
7 changes: 4 additions & 3 deletions src/Checks/PhpExtensionsAreInstalled.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace BeyondCode\SelfDiagnosis\Checks;

use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;

class PhpExtensionsAreInstalled implements Check
Expand Down Expand Up @@ -53,8 +54,8 @@ public function message(array $config): string
*/
public function check(array $config): bool
{
$this->extensions = Collection::make(array_get($config, 'extensions', []));
if (array_get($config, 'include_composer_extensions', false)) {
$this->extensions = Collection::make(Arr::get($config, 'extensions', []));
if (Arr::get($config, 'include_composer_extensions', false)) {
$this->extensions = $this->extensions->merge($this->getExtensionsRequiredInComposerFile());
$this->extensions = $this->extensions->unique();
}
Expand All @@ -75,7 +76,7 @@ public function getExtensionsRequiredInComposerFile()

$extensions = [];
foreach ($installedPackages as $installedPackage) {
$filtered = array_where(array_keys(array_get($installedPackage, 'require', [])), function ($value, $key) {
$filtered = Arr::where(array_keys(Arr::get($installedPackage, 'require', [])), function ($value, $key) {
return starts_with($value, self::EXT);
});
foreach ($filtered as $extension) {
Expand Down
5 changes: 3 additions & 2 deletions src/Checks/RedisCanBeAccessed.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace BeyondCode\SelfDiagnosis\Checks;

use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Redis;

class RedisCanBeAccessed implements Check
Expand All @@ -28,14 +29,14 @@ public function name(array $config): string
public function check(array $config): bool
{
try {
if (array_get($config, 'default_connection', true)) {
if (Arr::get($config, 'default_connection', true)) {
if (!$this->testConnection()) {
$this->message = trans('self-diagnosis::checks.redis_can_be_accessed.message.default_cache');
return false;
}
}

foreach (array_get($config, 'connections', []) as $connection) {
foreach (Arr::get($config, 'connections', []) as $connection) {
if (!$this->testConnection($connection)) {
$this->message = trans('self-diagnosis::checks.redis_can_be_accessed.message.named_cache', [
'name' => $connection,
Expand Down
9 changes: 5 additions & 4 deletions src/Checks/ServersArePingable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use BeyondCode\SelfDiagnosis\Exceptions\InvalidConfigurationException;
use BeyondCode\SelfDiagnosis\Server;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use JJG\Ping;

Expand Down Expand Up @@ -34,7 +35,7 @@ public function name(array $config): string
*/
public function check(array $config): bool
{
$this->notReachableServers = $this->parseConfiguredServers(array_get($config, 'servers', []));
$this->notReachableServers = $this->parseConfiguredServers(Arr::get($config, 'servers', []));
if ($this->notReachableServers->isEmpty()) {
return true;
}
Expand Down Expand Up @@ -94,9 +95,9 @@ private function parseConfiguredServers(array $servers): Collection
throw new InvalidConfigurationException('For servers in array notation, the host parameter is required.');
}

$host = array_get($server, 'host');
$port = array_get($server, 'port');
$timeout = array_get($server, 'timeout', self::DEFAULT_TIMEOUT);
$host = Arr::get($server, 'host');
$port = Arr::get($server, 'port');
$timeout = Arr::get($server, 'timeout', self::DEFAULT_TIMEOUT);

$result->push(new Server($host, $port, $timeout));
} else if (is_string($server)) {
Expand Down
5 changes: 3 additions & 2 deletions src/Checks/SupervisorProgramsAreRunning.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace BeyondCode\SelfDiagnosis\Checks;

use BeyondCode\SelfDiagnosis\SystemFunctions;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;

class SupervisorProgramsAreRunning implements Check
Expand Down Expand Up @@ -48,7 +49,7 @@ public function name(array $config): string
*/
public function check(array $config): bool
{
$this->notRunningPrograms = new Collection(array_get($config, 'programs', []));
$this->notRunningPrograms = new Collection(Arr::get($config, 'programs', []));
if ($this->notRunningPrograms->isEmpty()) {
return true;
}
Expand All @@ -69,7 +70,7 @@ public function check(array $config): bool
return false;
}

$restartedWithin = array_get($config, 'restarted_within', 0);
$restartedWithin = Arr::get($config, 'restarted_within', 0);
$programs = explode("\n" , $programs);
foreach ($programs as $program) {
/*
Expand Down

0 comments on commit cc347c1

Please sign in to comment.