Skip to content

Commit

Permalink
(chore): run format
Browse files Browse the repository at this point in the history
  • Loading branch information
FreakyWizard committed Nov 20, 2024
1 parent ace92ca commit f2735a1
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 206 deletions.
18 changes: 9 additions & 9 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
# PHP CS Fixer can be run by using the composer script `composer format`

$finder = Finder::create()
->in(__DIR__)
->name('*.php')
->notName('*.blade.php')
->ignoreDotFiles(true)
->ignoreVCS(true)
->exclude('public')
->exclude('node_modules')
->exclude('build')
->append(['.php-cs-fixer.php']);
->in(__DIR__)
->name('*.php')
->notName('*.blade.php')
->ignoreDotFiles(true)
->ignoreVCS(true)
->exclude('public')
->exclude('node_modules')
->exclude('build')
->append(['.php-cs-fixer.php']);

return Config::create($finder);
34 changes: 17 additions & 17 deletions config/skeleton-package.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@

return [

/*
|--------------------------------------------------------------------------
| Example Package
|--------------------------------------------------------------------------
|
| Configuration files provide a great way to customize your package.
|
| In most cases, you should provide sane defaults and publishing the config
| should be optional.
|
| Here, we'll define a few inspirational quotes for use in our component
| and console command.
|
*/
/*
|--------------------------------------------------------------------------
| Example Package
|--------------------------------------------------------------------------
|
| Configuration files provide a great way to customize your package.
|
| In most cases, you should provide sane defaults and publishing the config
| should be optional.
|
| Here, we'll define a few inspirational quotes for use in our component
| and console command.
|
*/

'quotes' => [
'For every Sage there is an Acorn.',
],
'quotes' => [
'For every Sage there is an Acorn.',
],
];
118 changes: 59 additions & 59 deletions configure.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,94 +5,94 @@

function ask(string $question, string $default = ''): string
{
$answer = readline($question.($default ? " ({$default})" : null).': ');
$answer = readline($question.($default ? " ({$default})" : null).': ');

if (! $answer) {
return $default;
}
if (! $answer) {
return $default;
}

return $answer;
return $answer;
}

function confirm(string $question, bool $default = false): bool
{
$answer = ask($question.' ('.($default ? 'Y/n' : 'y/N').')');
$answer = ask($question.' ('.($default ? 'Y/n' : 'y/N').')');

if (! $answer) {
return $default;
}
if (! $answer) {
return $default;
}

return strtolower($answer) === 'y';
return strtolower($answer) === 'y';
}

function writeln(string $line): void
{
echo $line.PHP_EOL;
echo $line.PHP_EOL;
}

function run(string $command): string
{
return trim((string) shell_exec($command));
return trim((string) shell_exec($command));
}

function str_after(string $subject, string $search): string
{
$pos = strrpos($subject, $search);
$pos = strrpos($subject, $search);

if (false === $pos) {
return $subject;
}
if (false === $pos) {
return $subject;
}

return substr($subject, $pos + strlen($search));
return substr($subject, $pos + strlen($search));
}

function slugify(string $subject): string
{
return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $subject), '-'));
return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $subject), '-'));
}

function title_case(string $subject): string
{
return str_replace(' ', '', ucwords(str_replace(['-', '_'], ' ', $subject)));
return str_replace(' ', '', ucwords(str_replace(['-', '_'], ' ', $subject)));
}

function replace_in_file(string $file, array $replacements): void
{
$contents = file_get_contents($file);

file_put_contents(
$file,
str_replace(
array_keys($replacements),
array_values($replacements),
$contents
)
);
$contents = file_get_contents($file);

file_put_contents(
$file,
str_replace(
array_keys($replacements),
array_values($replacements),
$contents
)
);
}

function determineSeparator(string $path): string
{
return str_replace('/', DIRECTORY_SEPARATOR, $path);
return str_replace('/', DIRECTORY_SEPARATOR, $path);
}

function replaceForWindows(): array
{
return preg_split('/\\r\\n|\\r|\\n/', run('dir /S /B * | findstr /v /i .git\ | findstr /v /i vendor | findstr /v /i '.basename(__FILE__).' | findstr /r /i /M /F:/ ":package :class Example SkeletonPackage"'));
return preg_split('/\\r\\n|\\r|\\n/', run('dir /S /B * | findstr /v /i .git\ | findstr /v /i vendor | findstr /v /i '.basename(__FILE__).' | findstr /r /i /M /F:/ ":package :class Example SkeletonPackage"'));
}

function replaceForAllOtherOSes(): array
{
return explode(PHP_EOL, run('grep -E -r -l -i ":class|:package|Example|SkeletonPackage" --exclude-dir=vendor ./* ./.github/* | grep -v '.basename(__FILE__)));
return explode(PHP_EOL, run('grep -E -r -l -i ":class|:package|Example|SkeletonPackage" --exclude-dir=vendor ./* ./.github/* | grep -v '.basename(__FILE__)));
}

function remove_readme_paragraphs(string $file): void
{
$contents = file_get_contents($file);
$contents = file_get_contents($file);

file_put_contents(
$file,
preg_replace('/<!--delete-->.*<!--\/delete-->/s', '', $contents) ?: $contents
);
file_put_contents(
$file,
preg_replace('/<!--delete-->.*<!--\/delete-->/s', '', $contents) ?: $contents
);
}

$currentDirectory = getcwd();
Expand All @@ -118,33 +118,33 @@ function remove_readme_paragraphs(string $file): void
writeln('This script will replace the above values in all relevant files in the project directory.');

if (! confirm('Modify files?', true)) {
exit(1);
exit(1);
}

$files = (str_starts_with(strtoupper(PHP_OS), 'WIN') ? replaceForWindows() : replaceForAllOtherOSes());

foreach ($files as $file) {
replace_in_file($file, [
':package_name' => $packageName,
'skeleton-package' => $packageSlug,
'Example' => $className,
'SkeletonPackage' => $nameSpace,
'example' => $classSlug,
':package_description' => $description,
]);

match (true) {
str_contains($file, determineSeparator('src/Example.php')) => rename($file, determineSeparator('./src/'.$className.'.php')),
str_contains($file, determineSeparator('src/SkeletonPackageServiceProvider.php')) => rename($file, determineSeparator('./src/'.$nameSpace.'ServiceProvider.php')),
str_contains($file, determineSeparator('src/Console/ExampleCommand.php')) => rename($file, determineSeparator('./src/Console/'.$className.'Command.php')),
str_contains($file, determineSeparator('src/Facades/Example.php')) => rename($file, determineSeparator('./src/Facades/'.$className.'.php')),
str_contains($file, determineSeparator('resources/views/example.blade.php')) => rename($file, determineSeparator('./resources/views/'.$classSlug.'.blade.php')),
str_contains($file, determineSeparator('tests/ExampleTest.php')) => rename($file, determineSeparator('./tests/'.$className.'Test.php')),
str_contains($file, determineSeparator('tests/Console/ExampleCommandTest.php')) => rename($file, determineSeparator('./tests/Console/'.$className.'CommandTest.php')),
str_contains($file, determineSeparator('tests/Facades/ExampleTest.php')) => rename($file, determineSeparator('./tests/Facades/'.$className.'Test.php')),
str_contains($file, 'README.md') => remove_readme_paragraphs($file),
default => [],
};
replace_in_file($file, [
':package_name' => $packageName,
'skeleton-package' => $packageSlug,
'Example' => $className,
'SkeletonPackage' => $nameSpace,
'example' => $classSlug,
':package_description' => $description,
]);

match (true) {
str_contains($file, determineSeparator('src/Example.php')) => rename($file, determineSeparator('./src/'.$className.'.php')),
str_contains($file, determineSeparator('src/SkeletonPackageServiceProvider.php')) => rename($file, determineSeparator('./src/'.$nameSpace.'ServiceProvider.php')),
str_contains($file, determineSeparator('src/Console/ExampleCommand.php')) => rename($file, determineSeparator('./src/Console/'.$className.'Command.php')),
str_contains($file, determineSeparator('src/Facades/Example.php')) => rename($file, determineSeparator('./src/Facades/'.$className.'.php')),
str_contains($file, determineSeparator('resources/views/example.blade.php')) => rename($file, determineSeparator('./resources/views/'.$classSlug.'.blade.php')),
str_contains($file, determineSeparator('tests/ExampleTest.php')) => rename($file, determineSeparator('./tests/'.$className.'Test.php')),
str_contains($file, determineSeparator('tests/Console/ExampleCommandTest.php')) => rename($file, determineSeparator('./tests/Console/'.$className.'CommandTest.php')),
str_contains($file, determineSeparator('tests/Facades/ExampleTest.php')) => rename($file, determineSeparator('./tests/Facades/'.$className.'Test.php')),
str_contains($file, 'README.md') => remove_readme_paragraphs($file),
default => [],
};
}

rename(determineSeparator('./config/skeleton-package.php'), determineSeparator('./config/'.$packageSlug.'.php'));
Expand Down
42 changes: 21 additions & 21 deletions src/Console/ExampleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@

class ExampleCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'example';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'example';

/**
* The console command description.
*
* @var string
*/
protected $description = 'My custom Acorn command.';
/**
* The console command description.
*
* @var string
*/
protected $description = 'My custom Acorn command.';

/**
* Execute the console command.
*/
public function handle(): void
{
$this->info(
Example::getQuote()
);
}
/**
* Execute the console command.
*/
public function handle(): void
{
$this->info(
Example::getQuote()
);
}
}
68 changes: 34 additions & 34 deletions src/Example.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,38 @@

class Example
{
/**
* Create a new Example instance.
*/
public function __construct(protected Application $app)
{
}

/**
* Retrieve a random inspirational quote.
*/
public function getQuote(): string
{
$quotes = config('skeleton-package.quotes');

Assert::isArray($quotes);

$quote = Arr::random(
$quotes
);

Assert::string($quote);

return $quote;
}

/**
* Retrieve a post content.
*/
public function getPostContent(int $postId): string
{
$post = \get_post($postId);

return $post ? $post->post_content : 'Post not found';
}
/**
* Create a new Example instance.
*/
public function __construct(protected Application $app)
{
}

/**
* Retrieve a random inspirational quote.
*/
public function getQuote(): string
{
$quotes = config('skeleton-package.quotes');

Assert::isArray($quotes);

$quote = Arr::random(
$quotes
);

Assert::string($quote);

return $quote;
}

/**
* Retrieve a post content.
*/
public function getPostContent(int $postId): string
{
$post = \get_post($postId);

return $post ? $post->post_content : 'Post not found';
}
}
14 changes: 7 additions & 7 deletions src/Facades/Example.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
*/
class Example extends Facade
{
/**
* Get the registered name of the component.
*/
protected static function getFacadeAccessor(): string
{
return 'Example';
}
/**
* Get the registered name of the component.
*/
protected static function getFacadeAccessor(): string
{
return 'Example';
}
}
Loading

0 comments on commit f2735a1

Please sign in to comment.