Skip to content

Commit

Permalink
psalm, tests, code style
Browse files Browse the repository at this point in the history
  • Loading branch information
reinvanoyen committed Dec 21, 2022
1 parent 7246ad4 commit 15d226d
Show file tree
Hide file tree
Showing 48 changed files with 645 additions and 132 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- master
- dev
- '*.x'
pull_request:

Expand Down Expand Up @@ -32,7 +33,7 @@ jobs:
- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-interaction

- name: Execute tests
run: composer run test

Expand Down
1 change: 0 additions & 1 deletion .phpunit.result.cache

This file was deleted.

13 changes: 11 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@
"php": "^7.4|^8.0",
"spatie/temporary-directory": "^1.3",
"intervention/image": "^2.7",
"ozdemirburak/iris": "^2.5"
"ozdemirburak/iris": "^2.5",
"spatie/laravel-tags": "^4.3",
"illuminate/support": "^8.0|^9.0",
"illuminate/database": "^8.0|^9.0",
"illuminate/http": "^8.0|^9.0",
"league/flysystem": "^3.12"
},
"require-dev": {
"orchestra/testbench": "^7.11",
"vimeo/psalm": "^5.4"
"vimeo/psalm": "^5.4",
"psalm/plugin-laravel": "^2.0"
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -54,6 +60,9 @@
],
"psalm": [
"./vendor/bin/psalm"
],
"psalm-info": [
"./vendor/bin/psalm --show-info=true"
]
}
}
4 changes: 2 additions & 2 deletions config/cmf.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
| The namespace of your Meta classes, excluding the application namespace.
| e.g. App\Cmf\Meta becomes Cmf\Meta
*/
'meta_namespace' => 'Cmf\\Meta',
'meta_namespace' => 'App\\Cmf\\Meta',

/*
|--------------------------------------------------------------------------
Expand All @@ -76,7 +76,7 @@
| The namespace of your Module classes, excluding the application namespace.
| e.g. App\Cmf\Modules becomes Cmf\Modules
*/
'modules_namespace' => 'Cmf\\Modules',
'modules_namespace' => 'App\\Cmf\\Modules',

/*
|--------------------------------------------------------------------------
Expand Down
14 changes: 12 additions & 2 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,19 @@
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<directory name="src"/>
<ignoreFiles>
<directory name="vendor" />
<directory name="vendor"/>
</ignoreFiles>
</projectFiles>
<issueHandlers>
<UndefinedClass>
<errorLevel type="suppress">
<referencedClass name="League\Flysystem\Util"/>
</errorLevel>
</UndefinedClass>
</issueHandlers>
<plugins>
<pluginClass class="Psalm\LaravelPlugin\Plugin"/>
</plugins>
</psalm>
27 changes: 17 additions & 10 deletions src/Action/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace ReinVanOyen\Cmf\Action;

use ReinVanOyen\Cmf\Contracts\{Exportable, Makeable};
use ReinVanOyen\Cmf\Exceptions\InvalidMetaException;
use ReinVanOyen\Cmf\Meta;
use ReinVanOyen\Cmf\Module;
use ReinVanOyen\Cmf\Traits\CanExport;
use ReinVanOyen\Cmf\Traits\CanBeMade;
Expand All @@ -18,14 +20,14 @@ abstract class Action implements Exportable, Makeable, \JsonSerializable
protected $meta;

/**
* @var Module $module
* @var string $moduleId
*/
private $moduleId;
private string $moduleId;

/**
* @var string $id
* @var string $actionId
*/
private $id;
private $actionId;

/**
* @var string $model
Expand All @@ -38,27 +40,32 @@ abstract class Action implements Exportable, Makeable, \JsonSerializable
protected $components;

/**
* @param string $id
* @param string $actionId
*/
final public function id(string $id)
final public function id(string $actionId)
{
$this->id = $id;
$this->actionId = $actionId;
}

/**
* @param string $meta
* @return $this
* @throws InvalidMetaException
*/
public function meta(string $meta)
{
if (! is_subclass_of($meta, Meta::class)) {
throw new InvalidMetaException();
}

$this->meta = $meta;
return $this;
}

/**
* @return string|null
* @return string
*/
public function getMeta(): ?string
public function getMeta(): string
{
return $this->meta;
}
Expand Down Expand Up @@ -86,7 +93,7 @@ final public function module(string $moduleId)

$this->export('path', [
'module' => $this->moduleId,
'action' => $this->id,
'action' => $this->actionId,
]);
}

Expand Down
1 change: 0 additions & 1 deletion src/Action/CollectionAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace ReinVanOyen\Cmf\Action;

use Illuminate\Http\Request;
use ReinVanOyen\Cmf\Components\Component;
use ReinVanOyen\Cmf\Filters\Filter;
use ReinVanOyen\Cmf\Http\Resources\ModelCollection;
use ReinVanOyen\Cmf\Sorters\Sorter;
Expand Down
2 changes: 1 addition & 1 deletion src/Action/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Create extends Action
private array $sidebar = [];

/**
* @var int $restrictByFk
* @var string $restrictByFk
*/
private $restrictByFk;

Expand Down
2 changes: 1 addition & 1 deletion src/Action/CreateWizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CreateWizard extends Action
private $steps;

/**
* @var int $restrictByFk
* @var string $restrictByFk
*/
private $restrictByFk;

Expand Down
20 changes: 11 additions & 9 deletions src/Action/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,26 @@ class Index extends CollectionAction

/**
* Index constructor.
*
* @param string $meta
* @param array $components
* @throws \ReinVanOyen\Cmf\Exceptions\InvalidMetaException
*/
public function __construct(string $meta, array $components = [])
{
$this->meta($meta);
$this->singular($meta::getSingular());
$this->plural($meta::getPlural());
$this->paginate($meta::getPerPage());
$this->components(count($components) ? $components : $meta::index());
$this->model = $meta::getModel();
$this->singular($this->getMeta()::getSingular());
$this->plural($this->getMeta()::getPlural());
$this->paginate($this->getMeta()::getPerPage());
$this->components(count($components) ? $components : $this->getMeta()::index());
$this->model = $this->getMeta()::getModel();

if (count($meta::getSearchColumns())) {
$this->search($meta::getSearchColumns());
if (count($this->getMeta()::getSearchColumns())) {
$this->search($this->getMeta()::getSearchColumns());
}

if ($this->meta::getSorting()) {
$this->sorter(StaticSorter::make($this->meta::getSorting()));
if ($this->getMeta()::getSorting()) {
$this->sorter(StaticSorter::make($this->getMeta()::getSorting()));
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/Cmf.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Cmf
/**
* @var ModuleRegistry $modules
*/
private $modules;
private ModuleRegistry $modules;

/**
* Cmf constructor.
Expand Down Expand Up @@ -50,8 +50,10 @@ public function registerModule($module)
{
$module = $this->modules->add($module);

foreach ($module->submodules() as $submodule) {
$this->modules->add($submodule, false);
if ($module) {
foreach ($module->submodules() as $submodule) {
$this->modules->add($submodule, false);
}
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/Components/BelongsToView.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,23 @@
use ReinVanOyen\Cmf\Http\Resources\ModelResource;
use ReinVanOyen\Cmf\RelationshipMetaGuesser;
use ReinVanOyen\Cmf\Support\Str;
use ReinVanOyen\Cmf\Traits\BuildsQuery;
use ReinVanOyen\Cmf\Traits\HasLabel;
use ReinVanOyen\Cmf\Traits\HasName;

class BelongsToView extends Component
{
use HasName;
use HasLabel;
use BuildsQuery;

/**
* @var string $titleColumn
*/
private $titleColumn;

/**
* BelongsToView constructor.
* @param string $name
* @param string|null $meta
* @throws \ReinVanOyen\Cmf\Exceptions\CouldntGuessMetaException
*/
public function __construct(string $name, string $meta = null)
{
Expand Down
1 change: 0 additions & 1 deletion src/Components/BooleanView.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace ReinVanOyen\Cmf\Components;

use Illuminate\Database\Eloquent\Model;
use ReinVanOyen\Cmf\Http\Resources\ModelResource;
use ReinVanOyen\Cmf\Traits\HasLabel;
use ReinVanOyen\Cmf\Traits\HasName;
Expand Down
14 changes: 0 additions & 14 deletions src/Components/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,11 @@ abstract class Component implements Exportable, Makeable, \JsonSerializable
use CanExport;
use CanBeMade;

/**
* @var int $id
*/
private $id;

/**
* @var Action $action
*/
protected $action;

/**
* @param int $id
*/
final public function setId(int $id)
{
$this->id = $id;
$this->export('id', $this->id);
}

/**
* @param Model $model
* @param Request $request
Expand Down
20 changes: 10 additions & 10 deletions src/Components/ManualOrderControls.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ public function type(): string

/**
* @param Request $request
* @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
* @return void
*/
public function apiSortUp(Request $request)
{
$sorter = $this->action->getSorter();
$sorter->sortUp($request);

return true;
if (method_exists($this->action, 'getSorter')) {
$sorter = $this->action->getSorter();
$sorter->sortUp($request);
}
}

/**
* @param Request $request
* @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
* @return void
*/
public function apiSortDown(Request $request)
{
$sorter = $this->action->getSorter();
$sorter->sortDown($request);

return true;
if (method_exists($this->action, 'getSorter')) {
$sorter = $this->action->getSorter();
$sorter->sortDown($request);
}
}
}
2 changes: 1 addition & 1 deletion src/Components/Tabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function provision(ModelResource $model, array &$attributes)
/**
* @param Model $model
* @param Request $request
* @return mixed|void
* @return void
*/
public function save(Model $model, Request $request)
{
Expand Down
7 changes: 4 additions & 3 deletions src/Components/TagsField.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use ReinVanOyen\Cmf\Http\Resources\ModelResource;
use ReinVanOyen\Cmf\Support\Str;
use ReinVanOyen\Cmf\Traits\HasLabel;
Expand Down Expand Up @@ -65,20 +66,20 @@ public function apiAutosuggest(Request $request)
$search = $request->input('search');
$tags = Tag::containing($search)->get();

return $tags->map(function ($tag) {
return $tags->map(function (Tag $tag) {
return $tag->name;
});
}

/**
* @param Request $request
* @return mixed
* @return \Illuminate\Database\Eloquent\Collection|Model[]|Collection|Tag[]
*/
public function apiLoad(Request $request)
{
$tags = Tag::all();

return $tags->map(function ($tag) {
return $tags->map(function (Tag $tag) {
return $tag->name;
});
}
Expand Down
Loading

0 comments on commit 15d226d

Please sign in to comment.