Skip to content

Commit

Permalink
Merge pull request #41 from koriym/spike
Browse files Browse the repository at this point in the history
Ask Email address
  • Loading branch information
koriym authored Apr 24, 2018
2 parents 2547647 + b45a605 commit 384c2de
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 58 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ As well as config file for popular continuous integration tool.
To create your project, enter the following command in your console.

```
composer create-project koriym/php-skeleton {project-path}
composer create-project koriym/php-skeleton <project-path>
```

You will be asked a few questions to configure the project:
Expand All @@ -36,6 +36,10 @@ What is the package name ?
What is your name ?
(Akihito Koriyama):
What is your email address ?
([email protected]):
```

## Composer Commands
Expand All @@ -59,11 +63,6 @@ Once installed, the project will automatically be configured so you can run thos
`composer cs-fix` run [`php-cs-fixer`](https://github.com/FriendsOfPHP/PHP-CS-Fixer) and [`phpcbf`](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Fixing-Errors-Automatically) to fix up the PHP code to follow the coding standards. (Check only command `compposer cs` is also available.)


### build

`composer build` run [`phploc`](https://github.com/sebastianbergmann/phploc), [`pdepend`](https://pdepend.org/) and [tests](#tests) above. It's handy for Jenkins.
You need "composer require phploc/phploc pdepend/pdepend --dev" for this.

## Setup continuous integration

* [Travis CI](https://docs.travis-ci.com/user/getting-started)
Expand Down
14 changes: 1 addition & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"@cs",
"vendor/bin/phpmd src,tests text ./phpmd.xml",
"vendor/bin/phpstan analyse -l max src tests -c phpstan.neon --no-progress",
"vendor/bin/phpunit"
"@test"
],
"coverage": ["php -dzend_extension=xdebug.so ./vendor/bin/phpunit --coverage-text --coverage-html=build/coverage"],
"cs": [
Expand All @@ -62,18 +62,6 @@
"cs-fix": [
"vendor/bin/php-cs-fixer fix -v",
"vendor/bin/phpcbf src tests"
],
"build": [
"rm -rf ./build; mkdir -p ./build/logs ./build/pdepend",
"pdepend --jdepend-xml=./build/logs/jdepend.xml --jdepend-chart=./build/pdepend/dependencies.svg --overview-pyramid=./build/pdepend/overview-pyramid.svg src",
"phploc --log-csv ./build/logs/phploc.csv src",
"@cs",
"@tests"
]
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
}
}
72 changes: 33 additions & 39 deletions src/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,19 @@ class Installer
* @var string
*/
private static $name;

/**
* @var string
*/
private static $email;

public static function preInstall(Event $event)
{
$io = $event->getIO();
$vendorClass = self::ask($io, 'What is the vendor name ?', 'MyVendor');
$packageClass = self::ask($io, 'What is the package name ?', 'MyPackage');
self::$name = self::ask($io, 'What is your name ?', self::getUserName());
self::$email = self::ask($io, 'What is your emaill address ?', self::getUserEmail());
$packageName = sprintf('%s/%s', self::camel2dashed($vendorClass), self::camel2dashed($packageClass));
$json = new JsonFile(Factory::getComposerFile());
$composerDefinition = self::getDefinition($vendorClass, $packageClass, $packageName, $json);
Expand Down Expand Up @@ -51,14 +57,7 @@ public static function postInstall(Event $event = null)
unlink(__FILE__);
}

/**
* @param IOInterface $io
* @param string $question
* @param string $default
*
* @return string
*/
private static function ask(IOInterface $io, $question, $default)
private static function ask(IOInterface $io, string $question, string $default) : string
{
$ask = [
sprintf("\n<question>%s</question>\n", $question),
Expand All @@ -69,47 +68,40 @@ private static function ask(IOInterface $io, $question, $default)
return $answer;
}

/**
* @param string $path
* @param callable $job
*/
private static function recursiveJob($path, $job)
private static function recursiveJob(string $path, callable $job)
{
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path), \RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $file) {
$job($file);
}
}

/**
* @param string $name
* @param string $vendor
* @param string $package
* @param string $packageName
* @param JsonFile $json
*
* @return array
*/
private static function getDefinition($vendor, $package, $packageName, JsonFile $json)
private static function getDefinition(string $vendor, string $package, string $packageName, JsonFile $json) : array
{
$composerDefinition = $json->read();
unset($composerDefinition['autoload']['files'], $composerDefinition['scripts']['pre-install-cmd'], $composerDefinition['scripts']['pre-update-cmd'], $composerDefinition['scripts']['post-create-project-cmd']);
unset(
$composerDefinition['autoload']['files'],
$composerDefinition['scripts']['pre-install-cmd'],
$composerDefinition['scripts']['pre-update-cmd'],
$composerDefinition['scripts']['post-create-project-cmd'],
$composerDefinition['keywords'],
$composerDefinition['homepage']
);

$composerDefinition['name'] = $packageName;
$composerDefinition['authors'] = [['name' => self::$name]];
$composerDefinition['authors'] = [
[
'name' => self::$name,
'email' => self::$email
]
];
$composerDefinition['description'] = '';
$composerDefinition['autoload']['psr-4'] = ["{$vendor}\\{$package}\\" => 'src/'];

return $composerDefinition;
}

/**
* @param string $vendor
* @param string $package
*
* @return \Closure
*/
private static function rename($vendor, $package)
private static function rename(string $vendor, string $package) : \Closure
{
$jobRename = function (\SplFileInfo $file) use ($vendor, $package) {
$fineName = $file->getFilename();
Expand All @@ -128,20 +120,22 @@ private static function rename($vendor, $package)
return $jobRename;
}

/**
* @param string $name
*
* @return string
*/
private static function camel2dashed($name)
private static function camel2dashed(string $name) : string
{
return strtolower(preg_replace('/([a-zA-Z])(?=[A-Z])/', '$1-', $name));
}

private static function getUserName()
private static function getUserName() : string
{
$author = `git config --global user.name`;

return $author ? trim($author) : '';
}

private static function getUserEmail() : string
{
$email = `git config --global user.email`;

return $email ? trim($email) : '';
}
}

0 comments on commit 384c2de

Please sign in to comment.