Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
Php 7.1 version (#91)
Browse files Browse the repository at this point in the history
| Q               | A
| --------------- | ---
| Bug fix?        | yes
| New feature?    | yes
| BC breaks?      | no
| Deprecations?   | no
| Related tickets | fixes #92,fixes #93
| License         | MIT
| Doc PR          | -
  • Loading branch information
prisis authored Nov 2, 2018
1 parent 80a50e9 commit aa853e0
Show file tree
Hide file tree
Showing 59 changed files with 425 additions and 355 deletions.
3 changes: 2 additions & 1 deletion .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ use Narrowspark\CS\Config\Config;
$config = new Config(null, [
'native_function_invocation' => [
'exclude' => [
'getcwd'
'getcwd',
],
],
'comment_to_phpdoc' => false,
]);
$config->getFinder()
->files()
Expand Down
15 changes: 14 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,26 @@ jobs:
fast_finish: true
allow_failures:
- php: nightly
- php: 7.3
include:
- stage: Test
php: 7.1
env: PHPUNIT=true SETUP=high REMOVE_XDEBUG=true
- stage: Test
php: 7.1
env: PHPUNIT=true SETUP=lowest REMOVE_XDEBUG=true
- stage: Test
php: 7.2
env: PHPUNIT=true SETUP=high REMOVE_XDEBUG=true
- stage: Test
php: 7.2
env: PHPUNIT=true SETUP=lowest REMOVE_XDEBUG=true
- stage: Test
php: 7.3
env: PHPUNIT=true SETUP=high REMOVE_XDEBUG=true
- stage: Test
php: 7.3
env: PHPUNIT=true SETUP=lowest REMOVE_XDEBUG=true
- stage: Test
php: nightly
env: PHPUNIT=true SETUP=high REMOVE_XDEBUG=true
Expand All @@ -77,7 +90,7 @@ jobs:
- bash <(curl -s https://codecov.io/bash)

- stage: Subsplit
if: (branch = master OR tag IS present)
if: (branch = master AND type = push) OR (tag IS present AND type = push)
php: 7.2
before_install:
- echo "skip"
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## v0.8.6

- Total issues resolved: **0**
- Total pull requests resolved: **1**
- Total contributors: **1**

### Changed

- [89: changed \n to PHP&#95;EOL](https://github.com/narrowspark/automatic/pull/89) thanks to @prisis

## v0.8.5

- Total issues resolved: **0**
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h1 align="center">Narrowspark Automatic</h1>
<p align="center">
<a href="https://github.com/narrowspark/automatic/releases"><img src="https://img.shields.io/packagist/v/narrowspark/automatic.svg?style=flat-square"></a>
<a href="https://php.net/"><img src="https://img.shields.io/badge/php-%5E7.2.0-8892BF.svg?style=flat-square"></a>
<a href="https://php.net/"><img src="https://img.shields.io/badge/php-%5E7.1.0-8892BF.svg?style=flat-square"></a>
<a href="https://codecov.io/gh/narrowspark/automatic"><img src="https://img.shields.io/codecov/c/github/narrowspark/automatic/master.svg?style=flat-square"></a>
<a href="#"><img src="https://img.shields.io/badge/style-level%207-brightgreen.svg?style=flat-square&label=phpstan"></a>
<a href="http://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square"></a>
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}
],
"require": {
"php": "^7.2",
"php": "^7.1",
"ext-mbstring": "*",
"ext-json": "*",
"ext-tokenizer": "*",
Expand All @@ -34,8 +34,8 @@
"require-dev": {
"composer/composer": "^1.6.0 || ^1.7.0",
"mockery/mockery": "^1.0.0",
"narrowspark/coding-standard": "^1.2.0",
"narrowspark/testing-helper": "^7.0.0",
"narrowspark/coding-standard": "^1.4.0",
"narrowspark/testing-helper": "^6.0.0",
"nyholm/nsa": "^1.1.0",
"phpunit/phpunit": "^7.2.0"
},
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ parameters:
- '#Parameter \#1 \$stream of class Symfony\\Component\\Console\\Output\\StreamOutput constructor expects resource, resource\|false given#'

- '#Call to an undefined method Composer\\DependencyResolver\\Operation\\OperationInterface\:\:getPackage#'
- '#Call to function method_exists\(\) with Symfony\\Component\\Filesystem\\Filesystem and #'

# Automatic
- '#does not call parent constructor from Composer\\Repository\\ComposerRepository#'
4 changes: 2 additions & 2 deletions src/Automatic/Automatic.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Automatic implements PluginInterface, EventSubscriberInterface
/**
* @var string
*/
public const VERSION = '0.8.5';
public const VERSION = '0.8.6';

/**
* @var string
Expand Down Expand Up @@ -632,7 +632,7 @@ public function onPostUpdate(Event $event, array $operations = []): void
'',
'<info>Some files may have been created or updated to configure your new packages.</info>',
'Please <comment>review</comment>, <comment>edit</comment> and <comment>commit</comment> them: these files are <comment>yours</comment>',
"\nTo show the package suggests run <comment>composer suggests</comment>"
\PHP_EOL . 'To show the package suggests run <comment>composer suggests</comment>'
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@ private function manipulateAndWrite(array $autoScripts): void
{
$this->manipulator->addSubNode('scripts', 'auto-scripts', $autoScripts);

\file_put_contents($this->json->getPath(), $this->manipulator->getContents());
$this->filesystem->dumpFile($this->json->getPath(), $this->manipulator->getContents());
}
}
2 changes: 1 addition & 1 deletion src/Automatic/Configurator/ComposerScriptsConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,6 @@ private function manipulateAndWrite(array $scripts): void
{
$this->manipulator->addMainKey('scripts', $scripts);

\file_put_contents($this->json->getPath(), $this->manipulator->getContents());
$this->filesystem->dumpFile($this->json->getPath(), $this->manipulator->getContents());
}
}
19 changes: 11 additions & 8 deletions src/Automatic/Configurator/EnvConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
use Narrowspark\Automatic\Common\Configurator\AbstractConfigurator;
use Narrowspark\Automatic\Common\Contract\Configurator as ConfiguratorContract;
use Narrowspark\Automatic\Common\Contract\Package as PackageContract;
use Narrowspark\Automatic\Configurator\Traits\AppendToFileTrait;

final class EnvConfigurator extends AbstractConfigurator
{
use AppendToFileTrait;

/**
* {@inheritdoc}
*/
Expand All @@ -32,8 +35,8 @@ public function configure(PackageContract $package): void
$data = '';

foreach ((array) $package->getConfig(ConfiguratorContract::TYPE, self::getName()) as $key => $value) {
if ($key[0] === '#' && \is_numeric(\mb_substr($key, 1))) {
$data .= '# ' . $value . "\n";
if (\mb_strpos($key, '#') === 0 && \is_numeric(\mb_substr($key, 1))) {
$data .= '# ' . $value . \PHP_EOL;

continue;
}
Expand All @@ -48,7 +51,7 @@ public function configure(PackageContract $package): void
$value = '"' . \str_replace(['\\', '"', "\t", "\n"], ['\\\\', '\\"', '\t', '\n'], $value) . '"';
}

$data .= $key . '=' . $value . "\n";
$data .= $key . '=' . $value . \PHP_EOL;
}

if (! \file_exists($this->path->getWorkingDir() . \DIRECTORY_SEPARATOR . '.env')) {
Expand All @@ -57,8 +60,8 @@ public function configure(PackageContract $package): void

$data = $this->markData($package->getPrettyName(), $data);

\file_put_contents($distenv, $data, \FILE_APPEND);
\file_put_contents($this->path->getWorkingDir() . \DIRECTORY_SEPARATOR . '.env', $data, \FILE_APPEND);
$this->appendToFile($distenv, $data);
$this->appendToFile($this->path->getWorkingDir() . \DIRECTORY_SEPARATOR . '.env', $data);
}

/**
Expand All @@ -75,10 +78,10 @@ public function unconfigure(PackageContract $package): void
if (! \file_exists($env)) {
continue;
}
/** @codeCoverageIgnoreEnd */
// @codeCoverageIgnoreEnd
$count = 0;
$contents = \preg_replace(
\sprintf('{%s*###> %s ###.*###< %s ###%s+}s', "\n", $package->getPrettyName(), $package->getPrettyName(), "\n"),
\sprintf('{###> %s ###.*###< %s ###%s+}s', $package->getPrettyName(), $package->getPrettyName(), \PHP_EOL),
'',
(string) \file_get_contents($env),
-1,
Expand All @@ -93,7 +96,7 @@ public function unconfigure(PackageContract $package): void

$this->write(\sprintf('Removing environment variables from %s', $file));

\file_put_contents($env, $contents);
$this->filesystem->dumpFile($env, (string) $contents);
}
}
}
15 changes: 9 additions & 6 deletions src/Automatic/Configurator/GitIgnoreConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
use Narrowspark\Automatic\Common\Configurator\AbstractConfigurator;
use Narrowspark\Automatic\Common\Contract\Configurator as ConfiguratorContract;
use Narrowspark\Automatic\Common\Contract\Package as PackageContract;
use Narrowspark\Automatic\Configurator\Traits\AppendToFileTrait;

final class GitIgnoreConfigurator extends AbstractConfigurator
{
use AppendToFileTrait;

/**
* {@inheritdoc}
*/
Expand All @@ -33,10 +36,10 @@ public function configure(PackageContract $package): void

foreach ((array) $package->getConfig(ConfiguratorContract::TYPE, self::getName()) as $value) {
$value = self::expandTargetDir($this->options, $value);
$data .= "${value}\n";
$data .= $value . \PHP_EOL;
}

\file_put_contents($gitignore, "\n" . \ltrim($this->markData($package->getPrettyName(), $data), "\r\n"), \FILE_APPEND);
$this->appendToFile($gitignore, \PHP_EOL . \ltrim($this->markData($package->getPrettyName(), $data), "\r\n"));
}

/**
Expand All @@ -50,11 +53,11 @@ public function unconfigure(PackageContract $package): void
if (! \file_exists($file)) {
return;
}
/** @codeCoverageIgnoreEnd */
// @codeCoverageIgnoreEnd
$count = 0;
$contents = \preg_replace(
\sprintf('{%s*###> %s ###.*###< %s ###%s+}s', "\n", $package->getPrettyName(), $package->getPrettyName(), "\n"),
"\n",
\sprintf('{###> %s ###.*###< %s ###%s+}s', $package->getPrettyName(), $package->getPrettyName(), \PHP_EOL),
\PHP_EOL,
(string) \file_get_contents($file),
-1,
$count
Expand All @@ -66,6 +69,6 @@ public function unconfigure(PackageContract $package): void

$this->write('Removed entries in .gitignore');

\file_put_contents($file, \ltrim($contents, "\r\n"));
$this->filesystem->dumpFile($file, \ltrim((string) $contents, "\r\n"));
}
}
44 changes: 44 additions & 0 deletions src/Automatic/Configurator/Traits/AppendToFileTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
namespace Narrowspark\Automatic\Configurator\Traits;

use Symfony\Component\Filesystem\Exception\IOException;

trait AppendToFileTrait
{
/**
* Appends content to an existing file.
*
* @see \Symfony\Component\Filesystem\Filesystem::appendToFile()
*
* @param string $filename The file to which to append content
* @param string $content The content to append
*
* @throws IOException If the file is not writable
*
* @return void
*/
public function appendToFile(string $filename, string $content): void
{
if (\method_exists($this->filesystem, 'appendToFile')) {
$this->filesystem->appendToFile($filename, $content);

return;
}
// @codeCoverageIgnoreStart
$dir = \dirname($filename);

if (! \is_dir($dir)) {
$this->filesystem->mkdir($dir);
}

if (! \is_writable($dir)) {
throw new IOException(\sprintf('Unable to write to the "%s" directory.', $dir), 0, null, $dir);
}

if (false === @\file_put_contents($filename, $content, \FILE_APPEND)) {
throw new IOException(\sprintf('Failed to write file "%s".', $filename), 0, null, $filename);
}
// @codeCoverageIgnoreEnd
}
}
2 changes: 1 addition & 1 deletion src/Automatic/Installer/InstallationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function run(): int
$status = $this->runInstaller($this->rootPackage, $this->whiteList);

if ($status !== 0) {
$this->io->writeError("\n" . '<error>Removal failed, reverting ' . Factory::getComposerFile() . ' to its original content.</error>');
$this->io->writeError(\PHP_EOL . '<error>Removal failed, reverting ' . Factory::getComposerFile() . ' to its original content.</error>');

\file_put_contents($this->jsonFile->getPath(), $this->composerBackup);
}
Expand Down
22 changes: 9 additions & 13 deletions src/Automatic/QuestionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,18 @@ final class QuestionFactory
*/
public static function getPackageQuestion(string $name, ?string $url): string
{
$message = <<<'PHP'
Do you want to execute this package [%s]?
[<comment>y</comment>] Yes
[<comment>n</comment>] No
[<comment>a</comment>] Yes for all packages, only for the current installation session
[<comment>p</comment>] Yes permanently, never ask again for this project
(defaults to <comment>n</comment>):
PHP;
$message = ' Do you want to execute this package [%s]?' . \PHP_EOL;
$message .= ' [<comment>y</comment>] Yes' . \PHP_EOL;
$message .= ' [<comment>n</comment>] No' . \PHP_EOL;
$message .= ' [<comment>a</comment>] Yes for all packages, only for the current installation session' . \PHP_EOL;
$message .= ' [<comment>p</comment>] Yes permanently, never ask again for this project' . \PHP_EOL;
$message .= ' (defaults to <comment>n</comment>): ' . \PHP_EOL;

if ($url === null) {
return \sprintf($message, $name);
}

return \sprintf(" Review the package from %s.\n" . $message, \str_replace('.git', '', $url), $name);
return \sprintf(' Review the package from %s.' . \PHP_EOL . $message, \str_replace('.git', '', $url), $name);
}

/**
Expand All @@ -41,10 +39,8 @@ public static function getPackageQuestion(string $name, ?string $url): string
*/
public static function getPackageScriptsQuestion(string $name): string
{
$message = <<<'PHP'
Do you want to add this package [%s] composer scripts?
(defaults to <comment>no</comment>):
PHP;
$message = ' Do you want to add this package [%s] composer scripts?' . \PHP_EOL;
$message .= ' (defaults to <comment>no</comment>): ' . \PHP_EOL;

return \sprintf($message, $name);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Automatic/ScriptExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function execute(string $type, string $cmd): void
$this->io->isDecorated()
);

/** @codeCoverageIgnoreStart */
// @codeCoverageIgnoreStart
$outputHandler = function ($type, $buffer) use ($cmdOutput): void {
$cmdOutput->write($buffer, false, OutputInterface::OUTPUT_RAW);
};
Expand All @@ -142,7 +142,7 @@ public function execute(string $type, string $cmd): void

\fseek($cmdOutput->getStream(), 0);

foreach (\explode("\n", (string) \stream_get_contents($cmdOutput->getStream())) as $line) {
foreach (\explode(\PHP_EOL, (string) \stream_get_contents($cmdOutput->getStream())) as $line) {
$this->io->writeError('!! ' . $line);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Automatic/SkeletonGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function run(): void
/** @var \Narrowspark\Automatic\Common\Generator\AbstractGenerator $generator */
$generator = $generators[$answer];

$this->io->write(\sprintf('%sGenerating [%s] skeleton.%s', "\n", $generatorTypes[$answer], "\n"));
$this->io->write(\sprintf('%sGenerating [%s] skeleton.%s', \PHP_EOL, $generatorTypes[$answer], \PHP_EOL));

$generator->generate();

Expand Down
2 changes: 1 addition & 1 deletion src/Common/Configurator/AbstractConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected function isFileMarked(string $packageName, string $file): bool
*/
protected function markData(string $packageName, string $data, int $spaceMultiplier = 0): string
{
return \sprintf("###> %s ###\n%s\n###< %s ###\n", $packageName, \rtrim($data, "\r\n"), $packageName);
return \sprintf('###> %s ###' . \PHP_EOL . '%s' . \PHP_EOL . '###< %s ###' . \PHP_EOL, $packageName, \rtrim($data, "\r\n"), $packageName);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Common/Installer/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private static function getPreferredInstallOptions(Config $config, InputInterfac
// noop
break;
}
/** @codeCoverageIgnoreEnd */
// @codeCoverageIgnoreEnd
$preferSource = self::getOption($input, 'prefer-source', $preferSource);
$preferDist = self::getOption($input, 'prefer-dist', $preferDist);

Expand Down
Loading

0 comments on commit aa853e0

Please sign in to comment.