Skip to content

Commit c4c0f5c

Browse files
committed
Add new method, add tests
1 parent e387eff commit c4c0f5c

File tree

67 files changed

+730
-102
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+730
-102
lines changed

.scrutinizer.yml

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,20 @@ checks:
1818
fix_identation_4spaces: true
1919
fix_doc_comments: true
2020

21-
build:
22-
tests:
23-
override:
24-
-
25-
command: 'vendor/bin/phpunit --coverage-clover=some-file'
26-
coverage:
27-
file: 'some-file'
28-
format: 'clover'
21+
tools:
22+
external_code_coverage:
23+
timeout: 600
24+
runs: 3
25+
php_analyzer: true
26+
php_code_coverage: false
27+
php_code_sniffer:
28+
config:
29+
standard: PSR2
30+
filter:
31+
paths: ['src']
32+
php_loc:
33+
enabled: true
34+
excluded_dirs: [vendor, tests]
35+
php_cpd:
36+
enabled: true
37+
excluded_dirs: [vendor, tests]

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,8 @@ php:
1313
before_script:
1414
- composer install
1515

16-
script: vendor/bin/phpunit
16+
script: vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover
17+
18+
after_script:
19+
- wget https://scrutinizer-ci.com/ocular.phar
20+
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,3 @@ composer Scripts composer event
2626
[link-travis]: https://travis-ci.org/Tekill/env-diff
2727
[link-scrutinizer]: https://scrutinizer-ci.com/g/Tekill/env-diff/code-structure/
2828
[link-code-quality]: https://scrutinizer-ci.com/g/Tekill/env-diff
29-
[link-author]: https://github.com/Tekill

composer.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@
1010
}
1111
],
1212
"require": {
13-
"php": ">=5.6"
13+
"php": ">=5.6",
14+
"symfony/console": "~2.8|~3.0"
1415
},
1516
"require-dev": {
1617
"composer/composer": "1.0.*@dev",
1718
"phpunit/phpunit": "^5.0"
1819
},
1920
"autoload": {
2021
"psr-4": { "LF\\EnvDiff\\": "src/" }
21-
}
22+
},
23+
"bin": [
24+
"env-diff"
25+
]
2226
}

env-diff

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
$autoloadPaths = [
5+
__DIR__ . '/../../autoload.php',
6+
__DIR__ . '/../vendor/autoload.php',
7+
__DIR__ . '/vendor/autoload.php'
8+
];
9+
10+
foreach ($autoloadPaths as $path) {
11+
if (file_exists($path)) {
12+
require_once $path;
13+
14+
$config = [];
15+
16+
$processor = new LF\EnvDiff\Processor(
17+
new \LF\EnvDiff\IO\ConsoleIO(
18+
new \Symfony\Component\Console\Input\ArgvInput(),
19+
new \Symfony\Component\Console\Output\ConsoleOutput()
20+
)
21+
);
22+
23+
$processor->actualizeEnv(LF\EnvDiff\Config::createFormArray($config));
24+
$processor->showDifference(LF\EnvDiff\Config::createFormArray($config));
25+
26+
exit(0);
27+
}
28+
}
29+
30+
fwrite(
31+
STDERR,
32+
'You need to set up the project dependencies using Composer:' . PHP_EOL . PHP_EOL .
33+
' composer install' . PHP_EOL . PHP_EOL .
34+
'You can learn all about Composer on https://getcomposer.org/.' . PHP_EOL
35+
);
36+
37+
exit(1);

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<filter>
1111
<whitelist>
12-
<directory>./</directory>
12+
<directory>./src</directory>
1313
<exclude>
1414
<directory>./tests</directory>
1515
<directory>./vendor</directory>

src/Composer/ScriptHandler.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Composer\Script\Event;
66
use InvalidArgumentException;
77
use LF\EnvDiff\Config;
8+
use LF\EnvDiff\IO\ComposerIO;
89
use LF\EnvDiff\Processor;
910
use RuntimeException;
1011

@@ -19,7 +20,7 @@ class ScriptHandler
1920
public static function actualizeEnv(Event $event)
2021
{
2122
$configs = self::extractConfigs($event);
22-
$processor = new Processor($event->getIO());
23+
$processor = new Processor(new ComposerIO($event->getIO()));
2324

2425
foreach ($configs as $config) {
2526
$processor->actualizeEnv(Config::createFormArray($config));
@@ -35,7 +36,7 @@ public static function actualizeEnv(Event $event)
3536
public static function showDifference(Event $event)
3637
{
3738
$configs = self::extractConfigs($event);
38-
$processor = new Processor($event->getIO());
39+
$processor = new Processor(new ComposerIO($event->getIO()));
3940

4041
foreach ($configs as $config) {
4142
$processor->showDifference(Config::createFormArray($config));

src/Config.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
class Config
66
{
7+
const DEFAULT_TARGET = '.env';
8+
CONST DEFAULT_DIST = '.env.dist';
9+
710
/** @var string */
811
private $dist;
912

@@ -13,6 +16,20 @@ class Config
1316
/** @var bool */
1417
private $keepOutdatedEnv;
1518

19+
/**
20+
* Config constructor.
21+
*
22+
* @param string $dist
23+
* @param string $target
24+
* @param bool $keepOutdatedEnv
25+
*/
26+
public function __construct($dist = self::DEFAULT_DIST, $target = self::DEFAULT_TARGET, $keepOutdatedEnv = true)
27+
{
28+
$this->dist = $dist;
29+
$this->target = $target;
30+
$this->keepOutdatedEnv = $keepOutdatedEnv;
31+
}
32+
1633
/**
1734
* @param array $config
1835
*
@@ -26,16 +43,11 @@ public static function createFormArray(array $config = [])
2643
if (empty($config['dist'])) {
2744
$config['dist'] = $config['target'] . '.dist';
2845
}
29-
if (empty($config['keep-outdated'])) {
46+
if (!isset($config['keep-outdated'])) {
3047
$config['keep-outdated'] = true;
3148
}
3249

33-
$self = new static();
34-
$self->target = $config['target'];
35-
$self->dist = $config['dist'];
36-
$self->keepOutdatedEnv = (bool) $config['keep-outdated'];
37-
38-
return $self;
50+
return new static($config['dist'], $config['target'], (bool) $config['keep-outdated']);
3951
}
4052

4153
/**

src/Env.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace LF\EnvDiff;
4+
5+
use InvalidArgumentException;
6+
use LF\EnvDiff\Env\Dumper;
7+
use LF\EnvDiff\Env\Parser;
8+
9+
class Env
10+
{
11+
/**
12+
* @param array $envArray
13+
*
14+
* @return string
15+
*/
16+
public static function dump(array $envArray)
17+
{
18+
return (new Dumper())->dump($envArray);
19+
}
20+
21+
/**
22+
* @param string $path
23+
*
24+
* @return array
25+
*
26+
* @throws InvalidArgumentException
27+
*/
28+
public static function parse($path)
29+
{
30+
return (new Parser())->parse($path);
31+
}
32+
}

src/Env/Dumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Dumper
99
*
1010
* @return string
1111
*/
12-
public static function dump(array $envArray)
12+
public function dump(array $envArray)
1313
{
1414
$dump = '';
1515

0 commit comments

Comments
 (0)