Skip to content

Commit 162fa62

Browse files
authored
Merge pull request phpro#643 from veewee/improve-project-path
Only show project files when project is in subfolder
2 parents 0fe62ca + 2a01af5 commit 162fa62

17 files changed

Lines changed: 338 additions & 54 deletions

File tree

resources/config/util.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ services:
55
grumphp.util.filesystem:
66
class: GrumPHP\Util\Filesystem
77
public: true
8+
arguments:
9+
- '@config'
810

911
grumphp.util.phpversion:
1012
class: GrumPHP\Util\PhpVersion
@@ -14,3 +16,4 @@ services:
1416
'7.0': '2018-12-03 23:59:59'
1517
'7.1': '2019-12-01 23:59:59'
1618
'7.2': '2020-11-30 23:59:59'
19+
'7.3': '2021-12-06 23:59:59'

spec/Console/Helper/PathsHelperSpec.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ class PathsHelperSpec extends ObjectBehavior
1616
function let(GrumPHP $config, Filesystem $filesystem, ExternalCommand $externalCommandLocator)
1717
{
1818
$this->beConstructedWith($config, $filesystem, $externalCommandLocator, '/grumphp.yml');
19+
20+
$filesystem->getProjectDir()->willReturn('/my/project');
21+
$filesystem->getGitDir()->willReturn('/my/project');
1922
}
2023

2124
function it_is_a_console_helper()

spec/Locator/ChangedFilesSpec.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@
1010
use GrumPHP\Locator\ChangedFiles;
1111
use GrumPHP\Util\Filesystem;
1212
use PhpSpec\ObjectBehavior;
13+
use Prophecy\Argument;
1314
use Prophecy\Prophet;
1415

1516
class ChangedFilesSpec extends ObjectBehavior
1617
{
1718
function let(Repository $repository, Filesystem $filesystem)
1819
{
1920
$this->beConstructedWith($repository, $filesystem);
21+
$filesystem->makePathRelativeToProjectDir(Argument::type('string'))->will(
22+
function (array $arguments): string {
23+
return $arguments[0];
24+
}
25+
);
2026
}
2127

2228
function it_is_initializable()

spec/Task/CloverCoverageSpec.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class CloverCoverageSpec extends ObjectBehavior
1818
function let(GrumPHP $grumPHP)
1919
{
2020
$grumPHP->getTaskConfiguration('clover_coverage')->willReturn([]);
21-
$this->beConstructedWith($grumPHP, new Filesystem());
21+
$this->beConstructedWith($grumPHP, new Filesystem($grumPHP->getWrappedObject()));
2222
}
2323

2424
function it_is_initializable()

spec/Util/FilesystemSpec.php

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/Composer/DevelopmentIntegrator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Composer\Script\Event;
88
use GrumPHP\Collection\ProcessArgumentsCollection;
99
use GrumPHP\Process\ProcessFactory;
10-
use GrumPHP\Util\Filesystem;
10+
use Symfony\Component\Filesystem\Filesystem;
1111

1212
class DevelopmentIntegrator
1313
{

src/Configuration/ContainerFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
namespace GrumPHP\Configuration;
66

7-
use GrumPHP\Util\Filesystem;
87
use Symfony\Component\Config\FileLocator;
98
use Symfony\Component\DependencyInjection\ContainerBuilder;
109
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
1110
use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
11+
use Symfony\Component\Filesystem\Filesystem;
1212

1313
final class ContainerFactory
1414
{
@@ -41,6 +41,7 @@ public static function buildFromConfiguration(string $path): ContainerBuilder
4141
if ($filesystem->exists($path)) {
4242
$loader->load($path);
4343
}
44+
$container->setParameter('config_file', $path);
4445

4546
// Compile configuration to make sure that tasks are added to the taskrunner
4647
$container->compile();

src/Configuration/GrumPHP.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ public function getGitDir(): string
3333
return $this->container->getParameter('git_dir');
3434
}
3535

36+
public function getConfigFile(): string
37+
{
38+
return $this->container->getParameter('config_file');
39+
}
40+
3641
public function getHooksDir(): ?string
3742
{
3843
return $this->container->getParameter('hooks_dir');

src/Console/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use GrumPHP\IO\ConsoleIO;
1010
use GrumPHP\Locator\ConfigurationFile;
1111
use GrumPHP\Util\ComposerFile;
12-
use GrumPHP\Util\Filesystem;
1312
use Monolog\Handler\StreamHandler;
1413
use Monolog\Logger;
1514
use Symfony\Component\Console\Application as SymfonyConsole;
@@ -21,6 +20,7 @@
2120
use Symfony\Component\Console\Output\ConsoleOutput;
2221
use Symfony\Component\Console\Output\OutputInterface;
2322
use Symfony\Component\DependencyInjection\ContainerBuilder;
23+
use Symfony\Component\Filesystem\Filesystem;
2424

2525
class Application extends SymfonyConsole
2626
{

src/Console/Helper/PathsHelper.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
/**
1616
* This class will return all configured paths relative to the working directory.
17+
* @deprecated Try to use Filesystem instead
18+
* @see Filesystem
1719
*/
1820
class PathsHelper extends Helper
1921
{
@@ -107,23 +109,24 @@ public function getAsciiContent(string $resource): string
107109
/**
108110
* This is the directory in which the cli script is initialized.
109111
* Normally this should be the directory where the composer.json file is located.
112+
*
113+
* @deprecated use Filesystem::getProjectDir() instead
114+
* @see Filesystem::getProjectDir()
110115
*/
111116
public function getWorkingDir(): string
112117
{
113-
return getcwd();
118+
return $this->fileSystem->getProjectDir();
114119
}
115120

116121
/**
117122
* Find the relative git directory.
123+
*
124+
* @deprecated use Filesystem::getRelativeGitDir() instead
125+
* @see Filesystem::getRelativeGitDir()
118126
*/
119127
public function getGitDir(): string
120128
{
121-
$gitDir = $this->config->getGitDir();
122-
if (!$this->fileSystem->exists($gitDir)) {
123-
throw new RuntimeException('The configured GIT directory could not be found.');
124-
}
125-
126-
return $this->getRelativePath($gitDir);
129+
return $this->fileSystem->getRelativeGitDir();
127130
}
128131

129132
/**

0 commit comments

Comments
 (0)