Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Apply fixes from StyleCI #3

Merged
merged 1 commit into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Commands/AddPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function handle()
}

if (!$path) {
$path = $this->anticipate('What is your package\'s path?', ['../packages/' . $name]);
$path = $this->anticipate('What is your package\'s path?', ['../packages/'.$name]);
}

if (!$branch) {
Expand All @@ -70,11 +70,11 @@ public function handle()
}

if ($branch === 'dev' || $branch === 'master') {
$branch = 'dev-' . $branch;
$branch = 'dev-'.$branch;
}

exec('composer config repositories.' . $name . ' ' . $type . ' ' . $path);
exec('composer config repositories.'.$name.' '.$type.' '.$path);
sleep(1);
exec('composer require "' . $vendor . '/' . $name . ':' . $branch . '"');
exec('composer require "'.$vendor.'/'.$name.':'.$branch.'"');
}
}
126 changes: 72 additions & 54 deletions src/Commands/MakePackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,37 +34,43 @@ class MakePackage extends Command

/**
* Name of the package.
* @var String
*
* @var string
*/
protected $packageName;

/**
* Directory where the package will be stored.
* @var String
*
* @var string
*/
protected $dir;

/**
* Copyright fields which will be placed inside the License.md file.
* @var String
*
* @var string
*/
protected $copyright;

/**
* The packages vendor name.
* @var String
*
* @var string
*/
protected $vendor;

/**
* The packages author.
* @var String
*
* @var string
*/
protected $author;

/**
* The mantainer's email address.
* @var String
*
* @var string
*/
protected $mail;

Expand All @@ -83,8 +89,9 @@ public function __construct(Filesystem $files)
/**
* Execute the console command.
*
* @return mixed
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*
* @return mixed
*/
public function handle()
{
Expand All @@ -109,10 +116,10 @@ public function handle()
$this->createTestCase($packagePath);

$this->callSilent('package:add', [
'name' => $this->packageName,
'path' => $this->dir . $this->packageName,
'vendor' => $this->vendor,
'branch' => 'master',
'name' => $this->packageName,
'path' => $this->dir.$this->packageName,
'vendor' => $this->vendor,
'branch' => 'master',
'--without-interaction' => true,
]);
}
Expand All @@ -132,7 +139,7 @@ public function checkForInputs()
$this->table(
['Name', 'Vendor', 'Directory', 'Author', 'E-mail', 'Copyright'],
[
[$name, $vendor, $dir, $author, $mail, $copyright]
[$name, $vendor, $dir, $author, $mail, $copyright],
]
);
}
Expand All @@ -142,55 +149,58 @@ public function checkForInputs()
*/
protected function createDirectories($path)
{
// create base path if it does not exist
if (! $this->alreadyExists( $this->getBasePath() )) {
$this->files->makeDirectory($this->getBasePath());
}
// create base path if it does not exist
if (!$this->alreadyExists($this->getBasePath())) {
$this->files->makeDirectory($this->getBasePath());
}

$this->files->makeDirectory($path);
$this->info('Package directory created successfully!');
$this->files->makeDirectory($path . '/src');
$this->files->makeDirectory($path.'/src');
$this->info('Source directory created successfully!');
$this->files->makeDirectory($path . '/tests');
$this->files->makeDirectory($path.'/tests');
$this->info('Tests directory created successfully!');
}

/**
* Create common files.
*
* @param $path
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
protected function createCommonFiles($path)
{
$this->files->put($path . '/readme.md', $this->buildFile('readme'));
$this->files->put($path . '/LICENSE.md', $this->buildFile('LICENSE'));
$this->files->put($path . '/CONTRIBUTING.md', $this->buildFile('CONTRIBUTING'));
$this->files->put($path . '/.travis.yml', $this->buildFile('.travis'));
$this->files->put($path . '/.syleci.yml', $this->buildFile('.styleci'));
$this->files->put($path . '/phpunit.xml', $this->buildFile('phpunit'));
$this->files->put($path . '/.gitignore', $this->buildFile('.gitignore'));
$this->files->put($path.'/readme.md', $this->buildFile('readme'));
$this->files->put($path.'/LICENSE.md', $this->buildFile('LICENSE'));
$this->files->put($path.'/CONTRIBUTING.md', $this->buildFile('CONTRIBUTING'));
$this->files->put($path.'/.travis.yml', $this->buildFile('.travis'));
$this->files->put($path.'/.syleci.yml', $this->buildFile('.styleci'));
$this->files->put($path.'/phpunit.xml', $this->buildFile('phpunit'));
$this->files->put($path.'/.gitignore', $this->buildFile('.gitignore'));
$this->info('Common files created successfully!');
}

/**
* @param $path
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
protected function createComposer($path)
{
$this->files->put($path . '/composer.json', $this->buildFile('composer'));
$this->files->put($path.'/composer.json', $this->buildFile('composer'));
$this->info('Composer created successfully!');
}

/**
* @param $path
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
protected function createServiceProvider($path)
{
$this->files->put(
$path . '/src/' . $this->getPackageName() . 'ServiceProvider.php',
$path.'/src/'.$this->getPackageName().'ServiceProvider.php',
$this->buildFile('src/provider')
);

Expand All @@ -200,7 +210,7 @@ protected function createServiceProvider($path)
protected function createTestCase($path)
{
$this->files->put(
$path . '/tests/TestCase.php',
$path.'/tests/TestCase.php',
$this->buildFile('tests/TestCase')
);

Expand All @@ -209,22 +219,25 @@ protected function createTestCase($path)

/**
* @param $name
* @return MakePackage
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*
* @return MakePackage
*/
protected function buildFile($name)
{
$stub = $this->files->get(__DIR__.'/../../resources/stubs/' . $name . '.stub');
$stub = $this->files->get(__DIR__.'/../../resources/stubs/'.$name.'.stub');

return $this->replaceNamespaces($stub)
->replaceNames($stub)
->replaceCredentials($stub);
}
}

/**
* Replace the namespace for the given stub.
*
* @param string $stub
* @param string $stub
*
* @return $this
*/
protected function replaceNamespaces(&$stub)
Expand All @@ -241,14 +254,15 @@ protected function replaceNamespaces(&$stub)
/**
* Replace the names for the given stub.
*
* @param string $stub
* @param string $stub
*
* @return $this
*/
protected function replaceNames(&$stub)
{
$stub = str_replace(
['DummyVendorName', 'DummyPackageName', 'DummyClass', 'CompanyOrVendorName'],
[$this->vendor, $this->packageName, $this->getPackageName() . 'ServiceProvider', $this->copyright],
[$this->vendor, $this->packageName, $this->getPackageName().'ServiceProvider', $this->copyright],
$stub
);

Expand All @@ -259,6 +273,7 @@ protected function replaceNames(&$stub)
* Replace Author credentials.
*
* @param $stub
*
* @return mixed
*/
protected function replaceCredentials(&$stub)
Expand All @@ -277,7 +292,7 @@ protected function replaceCredentials(&$stub)
*/
protected function getRootNamespace()
{
return ucfirst($this->vendor) . '\\' . $this->getPackageName();
return ucfirst($this->vendor).'\\'.$this->getPackageName();
}

/**
Expand All @@ -293,52 +308,53 @@ protected function getPackageName()
*/
protected function getComposerNamespace()
{
return ucfirst($this->vendor) . '\\\\' . $this->getNamespace();
return ucfirst($this->vendor).'\\\\'.$this->getNamespace();
}

/**
* @return string
*/
protected function getNamespace()
{
return ucfirst(camel_case($this->packageName)) . '\\\\';
return ucfirst(camel_case($this->packageName)).'\\\\';
}

/**
* @return string
*/
protected function getComposerProviderNamespace()
{
return $this->getComposerNamespace() . $this->getPackageName() . 'ServiceProvider';
return $this->getComposerNamespace().$this->getPackageName().'ServiceProvider';
}

/**
* Determine if the class already exists.
*
* @param $path
*
* @return bool
*/
protected function alreadyExists($path)
{
return $this->files->isDirectory($path);
}
/**
* @return string
*/
protected function getBasePath()
{
$path = ends_with($this->dir, '/') ? $this->dir : $this->dir . '/';
return base_path() . '/' . $path;
}
}

/**
* @return string
*/
protected function getBasePath()
{
$path = ends_with($this->dir, '/') ? $this->dir : $this->dir.'/';

return base_path().'/'.$path;
}

/**
* @return string
*/
protected function getPackagePath()
{
return $this->getBasePath() . $this->packageName;
return $this->getBasePath().$this->packageName;
}

/**
Expand All @@ -357,12 +373,12 @@ protected function getDirectoryInput()
}

return $this->dir;
;
}

/**
* Get copyright input.
* @return String
*
* @return string
*/
public function getCopyrightInput()
{
Expand Down Expand Up @@ -415,7 +431,8 @@ protected function getVendorInput()

/**
* Get the author name input.
* @return String
*
* @return string
*/
public function getAuthorInput()
{
Expand All @@ -432,7 +449,8 @@ public function getAuthorInput()

/**
* Get mail input.
* @return String
*
* @return string
*/
public function getMailInput()
{
Expand Down
6 changes: 3 additions & 3 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TestCase extends Orchestra
/**
* Get package providers.
*
* @param \Illuminate\Foundation\Application $app
* @param \Illuminate\Foundation\Application $app
*
* @return array
*/
Expand All @@ -23,12 +23,12 @@ protected function getPackageProviders($app)
/**
* Define environment setup.
*
* @param \Illuminate\Foundation\Application $app
* @param \Illuminate\Foundation\Application $app
*
* @return void
*/
protected function getEnvironmentSetUp($app)
{
$app['config']->set('app.key', '6rE9Nz59bGRbeMATftriyQjrpF7DcOQm');
}
}
}