Skip to content

Commit

Permalink
Fix coding standard
Browse files Browse the repository at this point in the history
Signed-off-by: Andi Rückauer <[email protected]>
  • Loading branch information
arueckauer committed Oct 5, 2021
1 parent c59d1fa commit 153f9cf
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 72 deletions.
28 changes: 16 additions & 12 deletions src/AutoComposer.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
<?php

declare(strict_types=1);

namespace Laminas\DevelopmentMode;

use function getenv;
use function is_resource;
use function printf;
use function var_export;

use const PHP_EOL;
use const STDERR;

/**
* Automatically switch to and from development mode based on type of composer
* install/update used.
Expand All @@ -17,26 +26,21 @@
*/
class AutoComposer
{
const COMPOSER_DEV_MODE = 'COMPOSER_DEV_MODE';
public const COMPOSER_DEV_MODE = 'COMPOSER_DEV_MODE';

/**
* @var value of COMPOSER_DEV_MODE
*/
/** @var string Value of COMPOSER_DEV_MODE */
private $composerDevMode;

/**
* @var resource
*/
/** @var resource */
private $errorStream;

/** @var string[] */
private $expectedValues = [
'0', // production mode
'1', // development mode
];

/**
* @param string Path to project.
*/
/** @var string Path to project. */
private $projectDir;

/**
Expand All @@ -46,8 +50,8 @@ class AutoComposer
public function __construct($projectDir = '', $errorStream = null)
{
$this->composerDevMode = getenv(self::COMPOSER_DEV_MODE);
$this->projectDir = $projectDir;
$this->errorStream = is_resource($errorStream) ? $errorStream : STDERR;
$this->projectDir = $projectDir;
$this->errorStream = is_resource($errorStream) ? $errorStream : STDERR;
}

/**
Expand Down
8 changes: 8 additions & 0 deletions src/Command.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
<?php

declare(strict_types=1);

namespace Laminas\DevelopmentMode;

use function array_shift;
use function count;
use function fwrite;

use const PHP_EOL;
use const STDERR;

class Command
{
/**
Expand Down
28 changes: 14 additions & 14 deletions src/ConfigDiscoveryTrait.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
<?php

declare(strict_types=1);

namespace Laminas\DevelopmentMode;

use RuntimeException;

use function file_exists;
use function is_array;
use function sprintf;
use function unlink;

use const PHP_EOL;

/**
* Shared functionality for the Disable/Enable commands.
*/
trait ConfigDiscoveryTrait
{
/**
* @var null|array
*/
/** @var null|array */
private $applicationConfig;

/**
* @var string
*/
/** @var string */
private $applicationConfigPath = 'config/application.config.php';

/**
* @var string
*/
/** @var string */
private $mezzioConfigPath = 'config/config.php';

/**
* @var string Base name for configuration cache.
*/
/** @var string Base name for configuration cache. */
private $configCacheBase = 'module-config-cache';

/**
Expand Down Expand Up @@ -109,8 +109,8 @@ private function getConfigCacheKey()
* Raises an exception if retrieved configuration is not an array.
*
* @return array
* @throws RuntimeException if config/application.config.php does not
* return an array
* @throws RuntimeException If config/application.config.php does not
* return an array.
*/
private function getApplicationConfig()
{
Expand Down
24 changes: 15 additions & 9 deletions src/Disable.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
<?php

declare(strict_types=1);

namespace Laminas\DevelopmentMode;

use RuntimeException;

use function file_exists;
use function fwrite;
use function is_resource;
use function sprintf;
use function unlink;

use const PHP_EOL;
use const STDERR;

class Disable
{
use ConfigDiscoveryTrait;

const DEVEL_CONFIG = 'config/development.config.php';
const DEVEL_LOCAL = 'config/autoload/development.local.php';
public const DEVEL_CONFIG = 'config/development.config.php';
public const DEVEL_LOCAL = 'config/autoload/development.local.php';

/**
* @var resource
*/
/** @var resource */
private $errorStream;

/**
* @param string Path to project.
*/
/** @var string Path to project. */
private $projectDir;

/**
Expand All @@ -28,7 +34,7 @@ class Disable
*/
public function __construct($projectDir = '', $errorStream = null)
{
$this->projectDir = $projectDir;
$this->projectDir = $projectDir;
$this->errorStream = is_resource($errorStream) ? $errorStream : STDERR;
}

Expand Down
32 changes: 21 additions & 11 deletions src/Enable.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
<?php

declare(strict_types=1);

namespace Laminas\DevelopmentMode;

use RuntimeException;

use function basename;
use function copy;
use function file_exists;
use function fwrite;
use function in_array;
use function is_resource;
use function sprintf;
use function symlink;

use const PHP_EOL;
use const PHP_OS;
use const STDERR;

class Enable
{
use ConfigDiscoveryTrait;

const DEVEL_CONFIG = 'config/development.config.php';
const DEVEL_CONFIG_DIST = 'config/development.config.php.dist';
const DEVEL_LOCAL = 'config/autoload/development.local.php';
const DEVEL_LOCAL_DIST = 'config/autoload/development.local.php.dist';
public const DEVEL_CONFIG = 'config/development.config.php';
public const DEVEL_CONFIG_DIST = 'config/development.config.php.dist';
public const DEVEL_LOCAL = 'config/autoload/development.local.php';
public const DEVEL_LOCAL_DIST = 'config/autoload/development.local.php.dist';

/**
* @var resource
*/
/** @var resource */
private $errorStream;

/**
* @param string Path to project.
*/
/** @var string Path to project. */
private $projectDir;

/**
Expand All @@ -30,7 +40,7 @@ class Enable
*/
public function __construct($projectDir = '', $errorStream = null)
{
$this->projectDir = $projectDir;
$this->projectDir = $projectDir;
$this->errorStream = is_resource($errorStream) ? $errorStream : STDERR;
}

Expand Down
10 changes: 6 additions & 4 deletions src/Help.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?php

declare(strict_types=1);

namespace Laminas\DevelopmentMode;

use function fwrite;
use function is_resource;

class Help
{
/**
* @var string
*/
private $message = <<< EOH
/** @var string */
private $message = <<<EOH
Enable/Disable development mode.
Usage:
Expand Down
12 changes: 8 additions & 4 deletions src/Status.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
<?php

declare(strict_types=1);

namespace Laminas\DevelopmentMode;

use function file_exists;
use function sprintf;

use const PHP_EOL;

class Status
{
const DEVEL_CONFIG = 'config/development.config.php';
public const DEVEL_CONFIG = 'config/development.config.php';

/**
* @param string
*/
/** @var string */
private $develConfigFile;

/**
Expand Down
14 changes: 11 additions & 3 deletions test/AutoComposerTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

declare(strict_types=1);

namespace LaminasTest\DevelopmentMode;

Expand All @@ -8,6 +9,13 @@
use org\bovigo\vfs\vfsStreamContainer;
use PHPUnit\Framework\TestCase;

use function fclose;
use function fopen;
use function is_resource;
use function putenv;

use const PHP_EOL;

class AutoComposerTest extends TestCase
{
use RemoveCacheFileTrait;
Expand All @@ -20,12 +28,12 @@ class AutoComposerTest extends TestCase

public function setUp(): void
{
$this->projectDir = vfsStream::setup('project', null, [
$this->projectDir = vfsStream::setup('project', null, [
'config' => [
'autoload' => [],
],
'cache' => [],
'data' => [],
'cache' => [],
'data' => [],
]);
$this->errorStream = fopen('php://memory', 'w+');
}
Expand Down
22 changes: 18 additions & 4 deletions test/DisableTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

declare(strict_types=1);

namespace LaminasTest\DevelopmentMode;

Expand All @@ -8,6 +9,16 @@
use org\bovigo\vfs\vfsStreamContainer;
use PHPUnit\Framework\TestCase;

use function fclose;
use function file_exists;
use function file_put_contents;
use function fopen;
use function fread;
use function fseek;
use function is_resource;

use const PHP_EOL;

class DisableTest extends TestCase
{
use RemoveCacheFileTrait;
Expand All @@ -26,15 +37,15 @@ class DisableTest extends TestCase

protected function setUp(): void
{
$this->projectDir = vfsStream::setup('project', null, [
$this->projectDir = vfsStream::setup('project', null, [
'config' => [
'autoload' => [],
],
'cache' => [],
'cache' => [],
]);
$this->errorStream = fopen('php://memory', 'w+');
$this->configStub = '<' . "?php\nreturn [];";
$this->command = new Disable(vfsStream::url('project'), $this->errorStream);
$this->configStub = '<' . "?php\nreturn [];";
$this->command = new Disable(vfsStream::url('project'), $this->errorStream);
}

protected function tearDown(): void
Expand All @@ -44,6 +55,9 @@ protected function tearDown(): void
}
}

/**
* @return bool|string
*/
public function readErrorStream()
{
fseek($this->errorStream, 0);
Expand Down
Loading

0 comments on commit 153f9cf

Please sign in to comment.