Skip to content
This repository was archived by the owner on Dec 8, 2017. It is now read-only.

Commit 6ff9b2b

Browse files
author
Samuel Parkinson
committed
Merge branch 'development'
2 parents 8222d02 + 4aac5f9 commit 6ff9b2b

25 files changed

+197
-159
lines changed

.gitattributes

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
# Remove unnecessary files from archive generation
44

55
## Files ##
6-
/.gitattributes export-ignore
7-
/.gitignore export-ignore
8-
/.travis.yml export-ignore
9-
/CONTRIBUTING.md export-ignore
10-
/LICENCE.md export-ignore
11-
/README.md export-ignore
12-
/phpunit.xml export-ignore
13-
/Vagrantfile export-ignore
6+
.gitattributes export-ignore
7+
.gitignore export-ignore
8+
.travis.yml export-ignore
9+
CONTRIBUTING.md export-ignore
10+
LICENCE.md export-ignore
11+
README.md export-ignore
12+
phpunit.xml export-ignore
13+
Vagrantfile export-ignore
1414

1515
## Folders ##
16-
/tests export-ignore
16+
tests/ export-ignore

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Project Files & Folders #
22
###########################
33
composer.lock
4+
*.sublime-*
45
.vagrant/
56
vendor/
6-
build/
77

88
# OS Generated Files #
99
######################

.travis.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,13 @@ php:
77
- hhvm
88
- hhvm-nightly
99

10-
addons:
11-
code_climate:
12-
repo_token: db3a9d5167930c783c659b6a713719a2f4b7fac416d579c024fbfce876c30c11
10+
cache:
11+
directories:
12+
- vendor/
1313

1414
before_script:
1515
- composer self-update
16-
- composer install --dev --no-interaction --prefer-source --optimize-autoloader
17-
- mkdir -p build/logs
16+
- composer install --no-interaction --optimize-autoloader
1817

1918
script:
2019
- vendor/bin/phpunit
21-
22-
after_script:
23-
- vendor/bin/test-reporter

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ An extendable framework for version control hooks.
99

1010
![StaticReview Success Demo](http://i.imgur.com/8G3uORp.gif)
1111

12-
[travis]: https://travis-ci.org/sjparkinson/static-review
13-
[packagist]: https://packagist.org/packages/sjparkinson/static-review
14-
[php]: https://php.net/
12+
[travis]: https://travis-ci.org/sjparkinson/static-review
13+
[packagist]: https://packagist.org/packages/sjparkinson/static-review
14+
[php]: https://php.net/
1515

1616
## Usage
1717

1818
Within a [composer][composer] managed project you can simply do the following...
1919

2020
```bash
21-
$ composer require sjparkinson/static-review:~1.1
21+
$ composer require sjparkinson/static-review:~1.0
2222
$ vendor/bin/static-review.php list hook
2323
```
2424

bin/static-review.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@
2020

2121
use Symfony\Component\Console\Application;
2222

23-
$name = 'StaticReview Command Line Tool';
23+
$name = 'StaticReview Command Line Tool';
2424
$version = '1.0.0';
2525

2626
$console = new Application($name, $version);
2727

2828
$console->addCommands([
2929
new HookListCommand,
3030
new HookInstallCommand,
31-
new HookRunCommand
31+
new HookRunCommand,
3232
]);
3333

3434
$console->run();

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838

3939
"require-dev": {
4040
"mockery/mockery": "~0.9",
41-
"phpunit/phpunit": "~4.0",
42-
"codeclimate/php-test-reporter": "~0.1"
41+
"phpunit/phpunit": "~4.0"
4342
},
4443

4544
"bin": [

hooks/php-pre-commit.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use StaticReview\Review\General\NoCommitTagReview;
2525
use StaticReview\Review\PHP\PhpLeadingLineReview;
2626
use StaticReview\Review\PHP\PhpLintReview;
27+
use StaticReview\Review\Config\ComposerConfigReview;
2728

2829
$reporter = new Reporter();
2930

@@ -33,7 +34,8 @@
3334
$review->addReview(new LineEndingsReview)
3435
->addReview(new PhpLeadingLineReview)
3536
->addReview(new NoCommitTagReview)
36-
->addReview(new PhpLintReview);
37+
->addReview(new PhpLintReview)
38+
->addReview(new ComposerConfigReview);
3739

3840
$git = VersionControlFactory::build(VersionControlFactory::SYSTEM_GIT);
3941

hooks/static-review-pre-commit.php

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

phpunit.xml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
1-
<phpunit
2-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
32
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
43

5-
bootstrap="./vendor/autoload.php"
4+
bootstrap="vendor/autoload.php"
65
colors="true"
76
verbose="true">
87

98
<!-- Test suites -->
109
<testsuites>
1110
<testsuite name="unit">
12-
<directory suffix="Test.php">tests/</directory>
11+
<directory>tests/</directory>
1312
</testsuite>
1413
</testsuites>
1514

1615
<!-- Coverage filter -->
1716
<filter>
1817
<whitelist>
19-
<directory>src</directory>
18+
<directory>src/</directory>
2019
</whitelist>
2120
</filter>
2221

2322
<!-- Coverage reporting -->
2423
<logging>
25-
<log type="coverage-clover" target="build/logs/clover.xml" />
26-
<log type="coverage-text" target="php://stdout" />
24+
<log type="coverage-text"
25+
target="php://stdout" />
2726
</logging>
2827

2928
</phpunit>

src/Command/HookInstallCommand.php

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,39 +27,63 @@ protected function configure()
2727

2828
$this->setDescription('Symlink a hook to the given target.');
2929

30-
$this->addArgument('hook', InputArgument::REQUIRED, 'The hook to link, either a path to a file or the filename of a hook in the hooks folder.')
31-
->addArgument('target', InputArgument::REQUIRED, 'The target location, including the filename (e.g. .git/hooks/pre-commit).');
30+
$this->addArgument('target', InputArgument::REQUIRED, 'The hook to link, either a path to a file or the filename of a hook in the hooks folder.')
31+
->addArgument('link', InputArgument::REQUIRED, 'The target location, including the filename (e.g. .git/hooks/pre-commit).');
3232

3333
$this->addOption('force', 'f', InputOption::VALUE_NONE, 'Overrite any existing files at the symlink target.');
3434
}
3535

3636
protected function execute(InputInterface $input, OutputInterface $output)
3737
{
38-
$source = realpath(__DIR__ . '/../../hooks/') . '/' . $input->getArgument('hook') . '.php';
38+
$force = $input->getOption('force');
39+
$target = $this->getTargetPath($input);
40+
$link = $input->getArgument('link');
3941

40-
if (! file_exists($source) && file_exists($input->getArgument('hook'))) {
41-
$source = $input->getArgument('hook');
42-
} else {
43-
$error = sprintf('<error>The hook %s does not exist!</error>', $input->getArgument('hook'));
44-
$output->writeln($error);
45-
exit(1);
42+
if ($output->isVeryVerbose()) {
43+
$message = sprintf('<info>Using %s for the hook target.</info>', $target);
44+
$output->writeln($message);
45+
46+
$message = sprintf('<info>Using %s for the hook path.</info>', $link);
47+
$output->writeln($message);
4648
}
4749

48-
$target = $input->getArgument('target');
49-
$force = $input->getOption('force');
50+
if (file_exists($link) && $force) {
51+
unlink($link);
5052

51-
if ($force && file_exists($target)) {
52-
unlink($target);
53-
$output->writeln('Removed existing file.');
53+
$message = sprintf('<info>Removed existing file at %s.</info>', $link);
54+
$output->writeln($message);
5455
}
5556

56-
if (file_exists($source)
57-
&& (! file_exists($target) || $force)) {
58-
symlink($source, $target);
59-
chmod($target, 0755);
57+
if (! file_exists($link) || $force) {
58+
symlink($target, $link);
59+
chmod($link, 0755);
6060
$output->writeln('Symlink created.');
6161
} else {
62-
$output->writeln('<error>A file at the target already exists.</error>');
62+
$message = sprintf('<error>A file at %s already exists.</error>', $link);
63+
$output->writeln($message);
64+
exit(1);
6365
}
6466
}
67+
68+
/**
69+
* @param $input InputInterface
70+
* @return string
71+
*/
72+
protected function getTargetPath(InputInterface $input)
73+
{
74+
if (file_exists($input->getArgument('target'))) {
75+
$target = realpath($input->getArgument('target'));
76+
} else {
77+
$path = '%s/%s.php';
78+
$target = sprintf($path, realpath(__DIR__ . '/../../hooks/'), $input->getArgument('target'));
79+
}
80+
81+
if (! file_exists($target)) {
82+
$error = sprintf('<error>The hook %s does not exist!</error>', $target);
83+
$output->writeln($error);
84+
exit(1);
85+
}
86+
87+
return $target;
88+
}
6589
}

0 commit comments

Comments
 (0)