Skip to content

Commit

Permalink
Merge pull request #1872 from nWidart/add-laravel-pint
Browse files Browse the repository at this point in the history
added and ran pint with laravel preset
  • Loading branch information
dcblogdev authored Jun 16, 2024
2 parents 4ab436a + 1e6bfd7 commit 9d50adc
Show file tree
Hide file tree
Showing 267 changed files with 1,300 additions and 1,280 deletions.
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"require": {
"php": ">=8.2",
"ext-json": "*",
"wikimedia/composer-merge-plugin": "^2.1"
"wikimedia/composer-merge-plugin": "^2.1",
"laravel/pint": "^1.16"
},
"require-dev": {
"phpunit/phpunit": "^11.0",
Expand Down Expand Up @@ -64,9 +65,10 @@
}
},
"scripts": {
"update-snapshots": "./vendor/bin/phpunit --no-coverage -d --update-snapshots",
"test": "vendor/bin/phpunit",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage",
"update-snapshots": "./phpunit --no-coverage -d --update-snapshots",
"lint": "pint",
"test": "phpunit",
"test-coverage": "phpunit --coverage-html coverage",
"pcf": "vendor/bin/php-cs-fixer fix --verbose"
},
"minimum-stability": "dev",
Expand Down
3 changes: 3 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"preset": "laravel"
}
32 changes: 14 additions & 18 deletions src/Activators/FileActivator.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,14 @@ public function __construct(Container $app)

/**
* Get the path of the file where statuses are stored
*
* @return string
*/
public function getStatusesFilePath(): string
{
return $this->statusesFile;
}

/**
* @inheritDoc
* {@inheritDoc}
*/
public function reset(): void
{
Expand All @@ -91,43 +89,43 @@ public function reset(): void
}

/**
* @inheritDoc
* {@inheritDoc}
*/
public function enable(Module $module): void
{
$this->setActiveByName($module->getName(), true);
}

/**
* @inheritDoc
* {@inheritDoc}
*/
public function disable(Module $module): void
{
$this->setActiveByName($module->getName(), false);
}

/**
* @inheritDoc
* {@inheritDoc}
*/
public function hasStatus(Module $module, bool $status): bool
{
if (!isset($this->modulesStatuses[$module->getName()])) {
if (! isset($this->modulesStatuses[$module->getName()])) {
return $status === false;
}

return $this->modulesStatuses[$module->getName()] === $status;
}

/**
* @inheritDoc
* {@inheritDoc}
*/
public function setActive(Module $module, bool $active): void
{
$this->setActiveByName($module->getName(), $active);
}

/**
* @inheritDoc
* {@inheritDoc}
*/
public function setActiveByName(string $name, bool $status): void
{
Expand All @@ -137,11 +135,11 @@ public function setActiveByName(string $name, bool $status): void
}

/**
* @inheritDoc
* {@inheritDoc}
*/
public function delete(Module $module): void
{
if (!isset($this->modulesStatuses[$module->getName()])) {
if (! isset($this->modulesStatuses[$module->getName()])) {
return;
}
unset($this->modulesStatuses[$module->getName()]);
Expand All @@ -159,12 +157,12 @@ private function writeJson(): void

/**
* Reads the json file that contains the activation statuses.
* @return array
*
* @throws FileNotFoundException
*/
private function readJson(): array
{
if (!$this->files->exists($this->statusesFile)) {
if (! $this->files->exists($this->statusesFile)) {
return [];
}

Expand All @@ -174,12 +172,12 @@ private function readJson(): array
/**
* Get modules statuses, either from the cache or from
* the json statuses file if the cache is disabled.
* @return array
*
* @throws FileNotFoundException
*/
private function getModulesStatuses(): array
{
if (!$this->config->get('modules.cache.enabled')) {
if (! $this->config->get('modules.cache.enabled')) {
return $this->readJson();
}

Expand All @@ -191,13 +189,11 @@ private function getModulesStatuses(): array
/**
* Reads a config parameter under the 'activators.file' key
*
* @param string $key
* @param $default
* @return mixed
*/
private function config(string $key, $default = null)
{
return $this->config->get('modules.activators.file.' . $key, $default);
return $this->config->get('modules.activators.file.'.$key, $default);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function toArray()
return array_map(function ($value) {
if ($value instanceof Module) {
$attributes = $value->json()->getAttributes();
$attributes["path"] = $value->getPath();
$attributes['path'] = $value->getPath();

return $attributes;
}
Expand Down
22 changes: 11 additions & 11 deletions src/Commands/Actions/CheckLangCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct()
{
parent::__construct();

$this->langPath = DIRECTORY_SEPARATOR . config('modules.paths.generator.lang.path', 'Resources/lang');
$this->langPath = DIRECTORY_SEPARATOR.config('modules.paths.generator.lang.path', 'Resources/lang');
}

public function executeAction($name): void
Expand All @@ -46,15 +46,15 @@ public function executeAction($name): void

}

public function getInfo(): string|null
public function getInfo(): ?string
{
return 'Checking languages ...';
}

private function getLangFiles($module)
{
$files = [];
$path = $module->getPath() . $this->langPath;
$path = $module->getPath().$this->langPath;
if (is_dir($path)) {
$files = array_merge($files, $this->laravel['files']->all($path));
}
Expand All @@ -65,18 +65,18 @@ private function getLangFiles($module)
private function getDirectories($module)
{
$moduleName = $module->getStudlyName();
$path = $module->getPath() . $this->langPath;
$path = $module->getPath().$this->langPath;
$directories = [];
if (is_dir($path)) {
$directories = $this->laravel['files']->directories($path);
$directories = array_map(function ($directory) use ($moduleName) {
return [
'name' => basename($directory),
'name' => basename($directory),
'module' => $moduleName,
'path' => $directory,
'files' => array_map(function ($file) {
'path' => $directory,
'files' => array_map(function ($file) {
return basename($file);
}, \File::glob($directory . DIRECTORY_SEPARATOR . "*")),
}, \File::glob($directory.DIRECTORY_SEPARATOR.'*')),
];
}, $directories);
}
Expand Down Expand Up @@ -136,14 +136,14 @@ private function checkMissingFiles(Collection $directories)
private function checkMissingKeys(Collection $directories)
{
//show missing keys
$uniqeLangFiles = $directories->pluck('files')->flatten()->unique();
$uniqeLangFiles = $directories->pluck('files')->flatten()->unique();
$langDirectories = $directories->pluck('name');

$missingKeysMessage = [];
$directories->each(function ($directory) use ($uniqeLangFiles, $langDirectories, &$missingKeysMessage) {

$uniqeLangFiles->each(function ($file) use ($directory, $langDirectories, &$missingKeysMessage) {
$langKeys = $this->getLangKeys($directory['path'] . DIRECTORY_SEPARATOR . $file);
$langKeys = $this->getLangKeys($directory['path'].DIRECTORY_SEPARATOR.$file);

if ($langKeys == false) {
return;
Expand All @@ -155,7 +155,7 @@ private function checkMissingKeys(Collection $directories)

$basePath = str_replace($directory['name'], $langDirectory, $directory['path']);

$otherLangKeys = $this->getLangKeys($basePath . DIRECTORY_SEPARATOR . $file);
$otherLangKeys = $this->getLangKeys($basePath.DIRECTORY_SEPARATOR.$file);

if ($otherLangKeys == false) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Actions/DisableCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function executeAction($name): void
});
}

public function getInfo(): string|null
public function getInfo(): ?string
{
return 'Disabling module ...';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Actions/DumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function executeAction($name): void
});
}

public function getInfo(): string|null
public function getInfo(): ?string
{
return 'Generating optimized autoload modules';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Actions/EnableCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function executeAction($name): void
});
}

public function getInfo(): string|null
public function getInfo(): ?string
{
return 'Disabling module ...';
}
Expand Down
12 changes: 6 additions & 6 deletions src/Commands/Actions/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function handle(): int
*/
protected function installFromFile(): int
{
if (!file_exists($path = base_path('modules.json'))) {
if (! file_exists($path = base_path('modules.json'))) {
$this->error("File 'modules.json' does not exist in your project root.");

return E_ERROR;
Expand All @@ -82,10 +82,10 @@ protected function installFromFile(): int
/**
* Install the specified module.
*
* @param string $name
* @param string $version
* @param string $type
* @param bool $tree
* @param string $name
* @param string $version
* @param string $type
* @param bool $tree
*/
protected function install($name, $version = 'dev-master', $type = 'composer', $tree = false)
{
Expand All @@ -110,7 +110,7 @@ protected function install($name, $version = 'dev-master', $type = 'composer', $

$installer->run();

if (!$this->option('no-update')) {
if (! $this->option('no-update')) {
$this->call('module:update', [
'module' => $installer->getModuleName(),
]);
Expand Down
10 changes: 3 additions & 7 deletions src/Commands/Actions/ModelPruneCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use InvalidArgumentException;

use function Laravel\Prompts\multiselect;

use Nwidart\Modules\Facades\Module;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Finder\Finder;

use function Laravel\Prompts\multiselect;

class ModelPruneCommand extends PruneCommand implements PromptsForMissingInput
{
public const ALL = 'All';
Expand Down Expand Up @@ -68,8 +67,6 @@ protected function promptForMissingArguments(InputInterface $input, OutputInterf

/**
* Determine the models that should be pruned.
*
* @return Collection
*/
protected function models(): Collection
{
Expand Down Expand Up @@ -105,7 +102,7 @@ protected function models(): Collection

$namespace = config('modules.namespace');

return $namespace . str_replace(
return $namespace.str_replace(
['/', '.php'],
['\\', ''],
Str::after($model->getRealPath(), realpath(config('modules.paths.modules')))
Expand All @@ -121,5 +118,4 @@ protected function models(): Collection
return $this->isPrunable($model);
})->values();
}

}
11 changes: 4 additions & 7 deletions src/Commands/Actions/ModelShowCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ class ModelShowCommand extends ShowModelCommand
/**
* Qualify the given model class base name.
*
* @param string $model
* @return string
*
* @see \Illuminate\Console\GeneratorCommand
*/
Expand All @@ -47,16 +45,15 @@ protected function qualifyModel(string $model): string

$rootNamespace = config('modules.namespace');

$modelPath = glob($rootNamespace . DIRECTORY_SEPARATOR .
'*' . DIRECTORY_SEPARATOR .
config('modules.paths.generator.model.path') . DIRECTORY_SEPARATOR .
$modelPath = glob($rootNamespace.DIRECTORY_SEPARATOR.
'*'.DIRECTORY_SEPARATOR.
config('modules.paths.generator.model.path').DIRECTORY_SEPARATOR.
"$model.php");

if (!count($modelPath)) {
if (! count($modelPath)) {
return $model;
}

return str_replace(['/', '.php'], ['\\', ''], $modelPath[0]);
}

}
5 changes: 3 additions & 2 deletions src/Commands/Actions/ModuleDeleteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

class ModuleDeleteCommand extends BaseCommand implements ConfirmableCommand
{
protected $name = 'module:delete';
protected $name = 'module:delete';

protected $description = 'Delete a module from the application';

public function executeAction($name): void
Expand All @@ -18,7 +19,7 @@ public function executeAction($name): void
});
}

public function getInfo(): string|null
public function getInfo(): ?string
{
return 'deleting module ...';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Actions/UnUseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function executeAction($name): void
});
}

public function getInfo(): string|null
public function getInfo(): ?string
{
return 'Forget Using Module ...';
}
Expand Down
Loading

0 comments on commit 9d50adc

Please sign in to comment.