diff --git a/.gitignore b/.gitignore index 5826402..9c10d38 100755 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ composer.phar composer.lock .DS_Store +.idea diff --git a/.php_cs b/.php_cs new file mode 100644 index 0000000..01874fd --- /dev/null +++ b/.php_cs @@ -0,0 +1,67 @@ +setRiskyAllowed(true) + //->setIndent("\t") + ->setRules([ + '@PHP56Migration' => true, + '@PHPUnit60Migration:risky' => true, + '@Symfony' => true, + '@Symfony:risky' => true, + 'align_multiline_comment' => true, + 'array_syntax' => ['syntax' => 'short'], + 'blank_line_before_statement' => true, + 'combine_consecutive_issets' => true, + 'combine_consecutive_unsets' => true, + 'compact_nullable_typehint' => true, + 'heredoc_to_nowdoc' => true, + 'list_syntax' => ['syntax' => 'long'], + 'method_argument_space' => ['ensure_fully_multiline' => true], + 'no_extra_consecutive_blank_lines' => ['tokens' => ['break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block']], + 'no_null_property_initialization' => true, + 'no_short_echo_tag' => true, + 'no_superfluous_elseif' => true, + 'no_unneeded_curly_braces' => true, + 'no_unneeded_final_method' => true, + 'no_unreachable_default_argument_value' => true, + 'no_useless_else' => true, + 'no_useless_return' => true, + 'ordered_class_elements' => true, + 'ordered_imports' => true, + 'php_unit_strict' => true, + 'phpdoc_scalar' => true, + 'php_unit_test_class_requires_covers' => true, + 'phpdoc_add_missing_param_annotation' => true, + 'phpdoc_order' => true, + 'phpdoc_indent' => true, + 'phpdoc_align' => ['tags' => []], + 'phpdoc_types_order' => true, + 'phpdoc_annotation_without_dot' => true, + 'semicolon_after_instruction' => true, + 'single_line_comment_style' => true, + 'strict_comparison' => true, + 'strict_param' => true, + 'yoda_style' => true, + ]) + ->setFinder( + PhpCsFixer\Finder::create() + ->exclude(['tests/Fixtures', 'node_modules', 'storage']) + ->notPath('_ide_helper.php') + ->in(__DIR__) + ) +; + +// special handling of fabbot.io service if it's using too old PHP CS Fixer version +try { + PhpCsFixer\FixerFactory::create() + ->registerBuiltInFixers() + ->registerCustomFixers($config->getCustomFixers()) + ->useRuleSet(new PhpCsFixer\RuleSet($config->getRules())); +} catch (PhpCsFixer\ConfigurationException\InvalidConfigurationException $e) { + $config->setRules([]); +} catch (UnexpectedValueException $e) { + $config->setRules([]); +} catch (InvalidArgumentException $e) { + $config->setRules([]); +} +return $config; \ No newline at end of file diff --git a/publishes/Dashboard/BlankPanel.php b/publishes/Dashboard/BlankPanel.php index 9bcfd45..e91d19f 100755 --- a/publishes/Dashboard/BlankPanel.php +++ b/publishes/Dashboard/BlankPanel.php @@ -6,5 +6,4 @@ class BlankPanel extends CoreBlankPanel { - // } diff --git a/publishes/Dashboard/DatabasePanel.php b/publishes/Dashboard/DatabasePanel.php index 55b6e70..9ae5e14 100755 --- a/publishes/Dashboard/DatabasePanel.php +++ b/publishes/Dashboard/DatabasePanel.php @@ -6,5 +6,4 @@ class DatabasePanel extends CoreDatabasePanel { - // } diff --git a/publishes/Dashboard/Factory.php b/publishes/Dashboard/Factory.php index 3404193..a6ce750 100755 --- a/publishes/Dashboard/Factory.php +++ b/publishes/Dashboard/Factory.php @@ -17,16 +17,16 @@ protected function registerPanels() { $this->dashboard ->row(function (DashboardRow $row) { - $row->panel(new BlankPanel)->setWidth(12); + $row->panel(new BlankPanel())->setWidth(12); }) // ->row(function (DashboardRow $row) { // $row->panel(new GoogleAnalyticsPanel)->setWidth(12); // }) ->row(function (DashboardRow $row) { - $row->panel(new MembersPanel)->setWidth(6); - $row->panel(new DatabasePanel)->setWidth(6); + $row->panel(new MembersPanel())->setWidth(6); + $row->panel(new DatabasePanel())->setWidth(6); }); return $this->dashboard; } -} \ No newline at end of file +} diff --git a/publishes/Dashboard/GoogleAnalyticsPanel.php b/publishes/Dashboard/GoogleAnalyticsPanel.php index 5196f62..5a7386f 100755 --- a/publishes/Dashboard/GoogleAnalyticsPanel.php +++ b/publishes/Dashboard/GoogleAnalyticsPanel.php @@ -6,5 +6,4 @@ class GoogleAnalyticsPanel extends CoreGoogleAnalyticsPanel { - // -} \ No newline at end of file +} diff --git a/publishes/Dashboard/MembersPanel.php b/publishes/Dashboard/MembersPanel.php index 977add9..72fab7e 100755 --- a/publishes/Dashboard/MembersPanel.php +++ b/publishes/Dashboard/MembersPanel.php @@ -6,5 +6,4 @@ class MembersPanel extends CoreMembersPanel { - // } diff --git a/publishes/Modules/Users.php b/publishes/Modules/Users.php index 4c95ee8..eaac855 100755 --- a/publishes/Modules/Users.php +++ b/publishes/Modules/Users.php @@ -5,11 +5,8 @@ use Terranet\Administrator\Modules\Users as CoreUsersModule; /** - * Administrator Users Module - * - * @package Terranet\Administrator + * Administrator Users Module. */ class Users extends CoreUsersModule { - // } diff --git a/publishes/Navigation.php b/publishes/Navigation.php index 0174f48..e56fd66 100755 --- a/publishes/Navigation.php +++ b/publishes/Navigation.php @@ -26,7 +26,7 @@ public function make() } /** - * Make SideBar navigation + * Make SideBar navigation. */ protected function makeSidebar() { @@ -76,4 +76,4 @@ protected function makeTools() ); }); } -} \ No newline at end of file +} diff --git a/publishes/config.php b/publishes/config.php index ecd4e6c..fada6ba 100755 --- a/publishes/config.php +++ b/publishes/config.php @@ -1,14 +1,14 @@ $prefix = 'cms', - 'title' => "Admin Architect", + 'title' => 'Admin Architect', 'abbreviation' => 'AA', 'welcome' => 'Welcome! Please sign In.', - # Authentication options + // Authentication options 'auth' => [ 'identity' => 'email', 'credential' => 'password', @@ -17,60 +17,60 @@ ], 'paths' => [ - # media storage + // media storage 'media' => 'media', - 'module' => "Http/Terranet/Administrator/Modules", - 'action' => "Http/Terranet/Administrator/Actions", - 'action_handler' => "Http/Terranet/Administrator/Actions/Handlers", - 'panel' => "Http/Terranet/Administrator/Dashboard", - 'finder' => "Http/Terranet/Administrator/Finders", - 'saver' => "Http/Terranet/Administrator/Savers", - 'column' => "Http/Terranet/Administrator/Decorators", - 'template' => "Http/Terranet/Administrator/Templates", - 'widget' => "Http/Terranet/Administrator/Widgets", - 'badge' => "Http/Terranet/Administrator/Badges", - 'breadcrumbs' => "Http/Terranet/Administrator/Breadcrumbs", + 'module' => 'Http/Terranet/Administrator/Modules', + 'action' => 'Http/Terranet/Administrator/Actions', + 'action_handler' => 'Http/Terranet/Administrator/Actions/Handlers', + 'panel' => 'Http/Terranet/Administrator/Dashboard', + 'finder' => 'Http/Terranet/Administrator/Finders', + 'saver' => 'Http/Terranet/Administrator/Savers', + 'column' => 'Http/Terranet/Administrator/Decorators', + 'template' => 'Http/Terranet/Administrator/Templates', + 'widget' => 'Http/Terranet/Administrator/Widgets', + 'badge' => 'Http/Terranet/Administrator/Badges', + 'breadcrumbs' => 'Http/Terranet/Administrator/Breadcrumbs', ], - # Handle passwords -> Convert plain text to Hash + // Handle passwords -> Convert plain text to Hash 'manage_passwords' => true, - # Enable File Manager + // Enable File Manager 'file_manager' => false, 'gravatar' => false, - # The menu item that should be used as the default landing page of the administrative section + // The menu item that should be used as the default landing page of the administrative section 'home_page' => $prefix, - # Basic user validation Rule + // Basic user validation Rule 'permission' => \Terranet\Administrator\Auth\SuperAdminRule::class, - # Navigation Factory + // Navigation Factory 'menu' => \Terranet\Administrator\Navigation\Factory::class, - # Dashboard Panels Factory + // Dashboard Panels Factory 'dashboard' => \App\Http\Terranet\Administrator\Dashboard\Factory::class, 'resource' => [ - # The custom way to resolve module name for custom resources - # when controller missing Router's $module parameter + // The custom way to resolve module name for custom resources + // when controller missing Router's $module parameter 'resolver' => null, - # Default segment for module name resolver - # /admin/pages - admin => 1, pages => 2 + // Default segment for module name resolver + // /admin/pages - admin => 1, pages => 2 'segment' => 2, ], 'acl' => [ - # Global ACL Manager, which used to control CRUD actions - # in the global way. Can provide optional methods: - # showIf, can(Index|Update|Delete|Create) + // Global ACL Manager, which used to control CRUD actions + // in the global way. Can provide optional methods: + // showIf, can(Index|Update|Delete|Create) 'manager' => null, ], - # main layouts + // main layouts 'layouts' => [ 'app' => 'administrator::layouts.app', 'popup' => 'administrator::layouts.popup', @@ -86,7 +86,7 @@ ], ], - # Exportable formats declaration + // Exportable formats declaration 'export' => [ 'default' => ['xml', 'csv', 'json'], // 'users' => ['csv', 'pdf'], @@ -95,9 +95,9 @@ 'translations' => [ 'enabled' => false, 'filters' => [ - # build filters based on specific translation files + // build filters based on specific translation files 'only' => null, // ['auth', 'validation'] - # except some translation files from filters + // except some translation files from filters 'except' => null, // ['password', 'pagination'] ], ], diff --git a/publishes/resources/js/theme.js b/publishes/resources/js/theme.js index a3f1f1d..6c47028 100644 --- a/publishes/resources/js/theme.js +++ b/publishes/resources/js/theme.js @@ -165,20 +165,16 @@ class AdminArchitect { } static handleDateControls() { - $('[data-filter-type="date"]').each((i, e) => { - let type = $(e).attr('type'); - - if ('date' === type) { - $(e).datepicker({ - format: 'yyyy-mm-dd', - clearBtn: false, - multidate: false, - }); - } + $('[data-filter-type="date"]').datetimepicker({ + format: 'YYYY-MM-DD' + }); - if ('datetime' === type) { - $(e).datetimepicker(); - } + $('[data-filter-type="time"]').datetimepicker({ + format: 'hh:mm:ss' + }); + + $('[data-filter-type="datetime"]').datetimepicker({ + format: 'YYYY-MM-DD hh:mm:ss' }); $('[data-filter-type="daterange"]').daterangepicker({ diff --git a/publishes/resources/js/vendor.js b/publishes/resources/js/vendor.js index 1c956f6..783f0ae 100755 --- a/publishes/resources/js/vendor.js +++ b/publishes/resources/js/vendor.js @@ -14,7 +14,6 @@ require('@adminarchitect/bootstrap/js/carousel'); require('@adminarchitect/bootstrap/js/transition'); /* Date/DateRange pickers */ -require('@adminarchitect/bootstrap-datepicker'); require('@adminarchitect/bootstrap-datetimepicker'); require('@adminarchitect/bootstrap-daterangepicker'); diff --git a/publishes/resources/sass/vendor.scss b/publishes/resources/sass/vendor.scss index 670db11..5ddb2ab 100755 --- a/publishes/resources/sass/vendor.scss +++ b/publishes/resources/sass/vendor.scss @@ -1,5 +1,4 @@ @import '~font-awesome/scss/font-awesome'; -@import "~@adminarchitect/bootstrap-datepicker/dist/css/bootstrap-datepicker3.css"; @import "~@adminarchitect/bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.css"; @import "~@adminarchitect/bootstrap-daterangepicker/daterangepicker"; @import "~selectize/dist/css/selectize.bootstrap3.css"; diff --git a/publishes/translations/en/actions.php b/publishes/translations/en/actions.php index 8c49314..60f09eb 100755 --- a/publishes/translations/en/actions.php +++ b/publishes/translations/en/actions.php @@ -17,5 +17,5 @@ 'global' => [ // 'remove_selected' => 'Delete collection' - ] + ], ]; diff --git a/publishes/translations/en/buttons.php b/publishes/translations/en/buttons.php index 02c23c6..4a428d8 100755 --- a/publishes/translations/en/buttons.php +++ b/publishes/translations/en/buttons.php @@ -17,9 +17,9 @@ 'logout' => 'Logout', 'batch_actions' => 'Batch Actions', 'clear_filters' => 'Clear', - 'media' => 'Media', - 'translations' => 'Translations', - 'upload' => 'Upload', - 'next' => 'Next', - 'previous' => 'Previous', + 'media' => 'Media', + 'translations' => 'Translations', + 'upload' => 'Upload', + 'next' => 'Next', + 'previous' => 'Previous', ]; diff --git a/publishes/translations/en/columns.php b/publishes/translations/en/columns.php index eaa7018..2d8c892 100755 --- a/publishes/translations/en/columns.php +++ b/publishes/translations/en/columns.php @@ -18,4 +18,4 @@ 'global' => [ // 'desc' => 'Description', ], -]; \ No newline at end of file +]; diff --git a/publishes/translations/en/dashboard.php b/publishes/translations/en/dashboard.php index 71c416b..e647041 100755 --- a/publishes/translations/en/dashboard.php +++ b/publishes/translations/en/dashboard.php @@ -2,18 +2,17 @@ return [ 'database' => [ - 'header' => 'Database stats', - 'header_engine' => 'Table / Engine', - 'header_rows' => 'Rows', - 'header_index' => 'Index Size', + 'header' => 'Database stats', + 'header_engine' => 'Table / Engine', + 'header_rows' => 'Rows', + 'header_index' => 'Index Size', 'header_collation' => 'Collation', ], - 'members' => [ - 'header' => 'Members', - 'header_total' => 'Total', - 'header_signed_last_week' => 'Signed Last Week', + 'members' => [ + 'header' => 'Members', + 'header_total' => 'Total', + 'header_signed_last_week' => 'Signed Last Week', 'header_signed_last_month' => 'Signed Last Month', - 'header_members_per_day' => 'Members per day', - + 'header_members_per_day' => 'Members per day', ], ]; diff --git a/publishes/translations/en/hints.php b/publishes/translations/en/hints.php index 5dfc166..53b987d 100755 --- a/publishes/translations/en/hints.php +++ b/publishes/translations/en/hints.php @@ -18,4 +18,4 @@ 'global' => [ // 'desc' => 'Description', ], -]; \ No newline at end of file +]; diff --git a/publishes/translations/en/media.php b/publishes/translations/en/media.php index 93051d0..adb7135 100755 --- a/publishes/translations/en/media.php +++ b/publishes/translations/en/media.php @@ -16,8 +16,8 @@ 'rename' => 'Rename file or folder', 'move' => 'Move files & folders', 'mkdir' => 'Create New Directory', - 'files' => "Files", - 'dropzone' => "Drop zone", + 'files' => 'Files', + 'dropzone' => 'Drop zone', 'file_info' => 'File info', 'buttons' => [ 'upload' => 'Upload', @@ -29,4 +29,4 @@ 'close' => 'Close', 'download' => 'Download', ], -]; \ No newline at end of file +]; diff --git a/publishes/translations/en/module.php b/publishes/translations/en/module.php index 3ecde3d..7d6b272 100755 --- a/publishes/translations/en/module.php +++ b/publishes/translations/en/module.php @@ -1,32 +1,32 @@ 'Administration panel', - 'success' => 'Success!', - 'error' => 'Error!', - 'settings' => 'Settings', - 'actions' => 'Actions', - 'login' => 'Sign In', - 'dashboard' => 'Dashboard', - 'filters' => 'Filters', + 'backend' => 'Administration panel', + 'success' => 'Success!', + 'error' => 'Error!', + 'settings' => 'Settings', + 'actions' => 'Actions', + 'login' => 'Sign In', + 'dashboard' => 'Dashboard', + 'filters' => 'Filters', 'credentials' => [ - 'email' => 'Email', + 'email' => 'Email', 'username' => 'Username', 'password' => 'Password', ], - 'resources' => [ - 'users' => 'Users', + 'resources' => [ + 'users' => 'Users', 'languages' => 'Languages', 'translations' => 'Translations', - 'settings' => 'Settings', + 'settings' => 'Settings', ], - 'groups' => [ + 'groups' => [ 'users' => 'Users', 'localization' => 'Localization', ], 'action' => [ 'create' => 'Create :resource', - 'edit' => ':instance', - 'view' => ':instance', - ] + 'edit' => ':instance', + 'view' => ':instance', + ], ]; diff --git a/publishes/translations/en/scopes.php b/publishes/translations/en/scopes.php index 7ad6f39..7c46319 100755 --- a/publishes/translations/en/scopes.php +++ b/publishes/translations/en/scopes.php @@ -18,4 +18,4 @@ 'global' => [ 'all' => 'All', ], -]; \ No newline at end of file +]; diff --git a/publishes/views/components/index/index.blade.php b/publishes/views/components/index/index.blade.php index bd2b691..6a9a0c8 100644 --- a/publishes/views/components/index/index.blade.php +++ b/publishes/views/components/index/index.blade.php @@ -1,8 +1,8 @@
- 'batch_action'])?> - + 'batch_action']); ?> + {{ $gridBefore or '' }} diff --git a/publishes/views/index/filters.blade.php b/publishes/views/index/filters.blade.php index 5fbac51..43d9562 100755 --- a/publishes/views/index/filters.blade.php +++ b/publishes/views/index/filters.blade.php @@ -5,13 +5,13 @@ $filled = $elements ? $elements->reduce(function ($filled, $element) { if ($element->getInput()->getValue()) { - $filled++; - }; + ++$filled; + } return $filled; }, 0) : 0; -$hasFilters = ($resetUrl != request()->fullUrl()) && $filled; +$hasFilters = ($resetUrl !== request()->fullUrl()) && $filled; ?> @if ($filter && $elements && $elements->count()) diff --git a/publishes/views/layouts/exportable.blade.php b/publishes/views/layouts/exportable.blade.php index faf120c..1bd6612 100644 --- a/publishes/views/layouts/exportable.blade.php +++ b/publishes/views/layouts/exportable.blade.php @@ -20,7 +20,7 @@ 'width: 100%; border-collapse: collapse; border: 1px solid #ccc;', - 'caption' => 'font-size: 16px; text-align: right; padding: 10px 0;' + 'caption' => 'font-size: 16px; text-align: right; padding: 10px 0;', ]; ?> diff --git a/publishes/views/view/index.blade.php b/publishes/views/view/index.blade.php index 2ba6cf9..c82d5c0 100755 --- a/publishes/views/view/index.blade.php +++ b/publishes/views/view/index.blade.php @@ -35,7 +35,7 @@ @endforeach
- setPlacement('sidebar')->filter() ?> + setPlacement('sidebar')->filter(); ?>
@foreach ($widgets->setPlacement('model')->filter() as $widget) diff --git a/publishes/views/view/relations/one_to_many.blade.php b/publishes/views/view/relations/one_to_many.blade.php index a6697cd..f9a1d3f 100755 --- a/publishes/views/view/relations/one_to_many.blade.php +++ b/publishes/views/view/relations/one_to_many.blade.php @@ -1,6 +1,6 @@ @if ($collection->count()) first())) + $titles = array_keys(\admin\helpers\eloquent_attributes($collection->first())); ?> diff --git a/src/Actions/Collection.php b/src/Actions/Collection.php index ac14262..1946f7f 100755 --- a/src/Actions/Collection.php +++ b/src/Actions/Collection.php @@ -24,12 +24,13 @@ public function __construct($items = []) * Find action by name. * * @param $name + * * @return mixed */ public function find($name) { return $this->first(function ($action) use ($name) { - return class_basename($action) == studly_case($name); + return class_basename($action) === studly_case($name); }); } @@ -38,6 +39,7 @@ public function find($name) * * @param User $user * @param Model $model + * * @return static */ public function authorized(User $user, Model $model = null) diff --git a/src/Actions/RemoveSelected.php b/src/Actions/RemoveSelected.php index 3e17fb3..0378169 100755 --- a/src/Actions/RemoveSelected.php +++ b/src/Actions/RemoveSelected.php @@ -16,6 +16,7 @@ class RemoveSelected * * @param Model $eloquent * @param Request $request + * * @return mixed */ public function handle(Model $eloquent, Request $request) @@ -29,6 +30,7 @@ public function handle(Model $eloquent, Request $request) * Check if deletion of each item is authorized. * * @param Model $eloquent + * * @return bool */ protected function canDelete(Model $eloquent) diff --git a/src/Actions/SaveOrder.php b/src/Actions/SaveOrder.php index 8096c01..2e3e6da 100755 --- a/src/Actions/SaveOrder.php +++ b/src/Actions/SaveOrder.php @@ -16,6 +16,7 @@ class SaveOrder * * @param Model $eloquent * @param Request $request + * * @return mixed */ public function handle(Model $eloquent, Request $request) diff --git a/src/ActionsManager.php b/src/ActionsManager.php index 3e77c61..3f5711b 100755 --- a/src/ActionsManager.php +++ b/src/ActionsManager.php @@ -24,14 +24,14 @@ class ActionsManager implements ActionsManagerContract * * @var array */ - protected $actions = null; + protected $actions; /** * List of global actions. * * @var array */ - protected $globalActions = null; + protected $globalActions; /** * Check if resource is readonly - has no actions. @@ -67,26 +67,6 @@ public function batch() return $this->scaffoldBatch(); } - /** - * Parse handler class for per-item and global actions. - * - * @return Collection - */ - protected function scaffoldActions() - { - return (new Collection($this->service->actions())); - } - - /** - * Parse handler class for per-item and global actions. - * - * @return Collection - */ - protected function scaffoldBatch() - { - return (new Collection($this->service->batchActions())); - } - /** * Determine if the user is authorized to make this request. * @@ -97,13 +77,13 @@ protected function scaffoldBatch() */ public function authorize($action, $model = null) { - # for most cases it is enough to set - # permissions in Resource object. + // for most cases it is enough to set + // permissions in Resource object. if (method_exists($this->module, 'authorize')) { return $this->module->authorize($action, $model); } - # Ask Actions Service for action permissions. + // Ask Actions Service for action permissions. return $this->service->authorize($action, $model, $this->module); } @@ -115,12 +95,12 @@ public function readonly() if (null === $this->readonly) { $this->readonly = false; - # check for ::hideActions() method. + // check for ::hideActions() method. if (method_exists($this->module, 'readonly')) { $this->readonly = $this->module->readonly(); } - # check for ::readonly() method. + // check for ::readonly() method. elseif (method_exists($this->service, 'readonly')) { $this->readonly = $this->service->readonly(); } @@ -160,4 +140,24 @@ public function exec($method, array $arguments = []) // Execute CRUD action return call_user_func_array([$this->service, $method], (array) $arguments); } + + /** + * Parse handler class for per-item and global actions. + * + * @return Collection + */ + protected function scaffoldActions() + { + return new Collection($this->service->actions()); + } + + /** + * Parse handler class for per-item and global actions. + * + * @return Collection + */ + protected function scaffoldBatch() + { + return new Collection($this->service->batchActions()); + } } diff --git a/src/Auth/SuperAdminRule.php b/src/Auth/SuperAdminRule.php index dc7793a..90916bd 100755 --- a/src/Auth/SuperAdminRule.php +++ b/src/Auth/SuperAdminRule.php @@ -18,6 +18,6 @@ public function validate(Authenticatable $user = null) return call_user_func([$user, 'isSuperAdmin']); } - return (1 === (int) $user->getAuthIdentifier()); + return 1 === (int) $user->getAuthIdentifier(); } -} \ No newline at end of file +} diff --git a/src/AuthUserProvider.php b/src/AuthUserProvider.php index f83939a..7ab5c3b 100755 --- a/src/AuthUserProvider.php +++ b/src/AuthUserProvider.php @@ -6,9 +6,7 @@ use Terranet\Administrator\Traits\CallableTrait; /** - * Class AuthUserProvider - * - * @package Terranet\Administrator + * Class AuthUserProvider. */ class AuthUserProvider extends EloquentUserProvider { @@ -22,7 +20,7 @@ public function retrieveByCredentials(array $credentials) $query = $this->createModel()->newQuery(); foreach ($credentials as $key => $value) { - if (! str_contains($key, 'password')) { + if (!str_contains($key, 'password')) { // handle closures $value = $this->retrieveValue($value); @@ -35,15 +33,17 @@ public function retrieveByCredentials(array $credentials) /** * @param $value + * * @return string */ protected function searchMethod($value) { - return is_array($value) ? "whereIn" : "where"; + return is_array($value) ? 'whereIn' : 'where'; } /** * @param $value + * * @return mixed */ protected function retrieveValue($value) diff --git a/src/Badges/Collection.php b/src/Badges/Collection.php index ec411d6..ee9185c 100755 --- a/src/Badges/Collection.php +++ b/src/Badges/Collection.php @@ -1,6 +1,5 @@ items = collect($items); @@ -33,7 +32,7 @@ public function __construct($items = [], \Closure $transformer) } /** - * Transform items according to $transformer closure + * Transform items according to $transformer closure. * * @return static */ diff --git a/src/Collection/Group.php b/src/Collection/Group.php index cc058d7..4ea5ffb 100755 --- a/src/Collection/Group.php +++ b/src/Collection/Group.php @@ -2,7 +2,6 @@ namespace Terranet\Administrator\Collection; -use Coduo\PHPHumanizer\StringHumanizer; use Terranet\Administrator\Collection\Mutable as MutableCollection; use Terranet\Administrator\Columns\Element; use Terranet\Administrator\Traits\Collection\ElementContainer; @@ -27,9 +26,10 @@ public function __construct($id) } /** - * Push an + * Push an. * * @param $element + * * @return $this */ public function push(Element $element) @@ -51,6 +51,7 @@ public function merge($elements = []) * * @param $element * @param $position + * * @return $this */ public function insert(Element $element, $position) @@ -64,6 +65,7 @@ public function insert(Element $element, $position) * Remove an element from collection. * * @param $id + * * @return static */ public function without($id) @@ -78,6 +80,7 @@ public function without($id) * * @param $id * @param \Closure $callback + * * @return $this */ public function update($id, \Closure $callback) @@ -91,6 +94,7 @@ public function update($id, \Closure $callback) * Update many elements at once. * * @param $ids + * * @return $this */ public function updateMany(array $ids = []) @@ -105,6 +109,7 @@ public function updateMany(array $ids = []) * * @param $id * @param $position + * * @return $this */ public function move($id, $position) @@ -118,6 +123,7 @@ public function move($id, $position) * Run a map over each of the items. * * @param callable $callback + * * @return static */ public function map(callable $callback) @@ -131,6 +137,7 @@ public function map(callable $callback) * Find element by ID. * * @param $id + * * @return mixed */ public function find($id) @@ -147,4 +154,4 @@ public function isGroup() { return true; } -} \ No newline at end of file +} diff --git a/src/Collection/Mutable.php b/src/Collection/Mutable.php index bfa7f83..95f670f 100755 --- a/src/Collection/Mutable.php +++ b/src/Collection/Mutable.php @@ -14,7 +14,8 @@ class Mutable extends BaseCollection * Push an item onto the end of the collection. * * @param mixed $element - * @param Closure|null $callback + * @param null|Closure $callback + * * @return $this */ public function push($element, Closure $callback = null) @@ -32,9 +33,9 @@ public function push($element, Closure $callback = null) /** * @param string $collection - * - * @param Closure|null $callback + * @param null|Closure $callback * @param null $position + * * @return $this */ public function media($collection = 'default', Closure $callback = null, $position = null) @@ -55,7 +56,8 @@ public function media($collection = 'default', Closure $callback = null, $positi * * @param $element * @param $position - * @param Closure|null $callback + * @param null|Closure $callback + * * @return $this */ public function insert($element, $position, Closure $callback = null) @@ -76,7 +78,7 @@ public function insert($element, $position, Closure $callback = null) return $this->push($element); } - if ($position === 0) { + if (0 === $position) { return $this->prepend($element); } @@ -96,7 +98,8 @@ public function insert($element, $position, Closure $callback = null) /** * Remove an element(s) from collection. * - * @param int|array $id + * @param array|int $id + * * @return static */ public function without($id) @@ -106,7 +109,7 @@ public function without($id) } $items = $this->filter(function ($element) use ($id) { - return !in_array($element->id(), $id); + return !in_array($element->id(), $id, true); })->all(); $this->items = array_values($items); @@ -130,6 +133,7 @@ public function standalone($columns) * * @param $id * @param Closure $callback + * * @return $this */ public function update($id, Closure $callback) @@ -157,6 +161,7 @@ public function update($id, Closure $callback) * Update many elements at once. * * @param $ids + * * @return $this */ public function updateMany(array $ids = []) @@ -172,13 +177,15 @@ public function updateMany(array $ids = []) * Move element. * * @param $id - * @param mixed|int|string $position + * @param int|mixed|string $position + * + * @throws Exception + * * @return static * * @example: move('user_id', 4); * @example: move('user_id', 'before:name"); * @example: move('user_id', 'after:id"); - * @throws Exception */ public function move($id, $position) { @@ -197,27 +204,12 @@ public function move($id, $position) throw new Exception("Unknown moving direction: {$position}"); } - /** - * Move an element to a position. - * - * @param $id - * @param $position - * @return static - */ - protected function toPosition($id, $position) - { - $element = $this->find($id); - - return $this - ->without($id) - ->insert($element, $position); - } - /** * Move element before another one. * * @param $id * @param $target + * * @return $this */ public function moveBefore($id, $target) @@ -239,6 +231,7 @@ public function moveBefore($id, $target) * * @param $id * @param $target + * * @return $this */ public function moveAfter($id, $target) @@ -261,6 +254,7 @@ public function moveAfter($id, $target) * * @param $id * @param Closure $callback + * * @return $this */ public function group($id, Closure $callback) @@ -280,6 +274,7 @@ public function group($id, Closure $callback) * @param $elements * @param $groupId * @param null $position + * * @return $this */ public function join($elements, $groupId, $position = null) @@ -287,7 +282,7 @@ public function join($elements, $groupId, $position = null) $group = new Group($groupId); $this->filter(function ($element) use ($elements) { - return in_array($element->id(), $elements); + return in_array($element->id(), $elements, true); })->each(function ($element) use ($group) { $group->push($element); $this->items = $this->without($element->id())->all(); @@ -306,6 +301,7 @@ public function join($elements, $groupId, $position = null) * Build a collection. * * @param $decorator + * * @return static */ public function build($decorator) @@ -327,17 +323,18 @@ public function build($decorator) * Find an element. * * @param $id + * * @return mixed */ public function find($id) { $element = $this->first(function ($element) use ($id) { - return $element->id() == $id; + return $element->id() === $id; }); if (!$element) { $this->notFound($id); - }; + } return $element; } @@ -346,23 +343,41 @@ public function find($id) * Find an element position. * * @param $id - * @return int|null|string + * + * @return null|int|string */ public function position($id) { $i = 0; foreach ($this->all() as $item) { - if ($item->id() == $id) { + if ($item->id() === $id) { // stop immediately when victim found. return $i; } - $i++; + ++$i; } $this->notFound($id); } + /** + * Move an element to a position. + * + * @param $id + * @param $position + * + * @return static + */ + protected function toPosition($id, $position) + { + $element = $this->find($id); + + return $this + ->without($id) + ->insert($element, $position); + } + protected function notFound($id) { throw new Exception(sprintf('Element [%s] does not exist.', $id)); @@ -372,6 +387,7 @@ protected function notFound($id) * Create element object from string. * * @param $element + * * @return mixed */ protected function createElement($element) @@ -385,6 +401,7 @@ protected function createElement($element) /** * @param $collection + * * @return MediaElement */ protected function createMediaElement($collection) diff --git a/src/Columns/Decorators/AttachmentDecorator.php b/src/Columns/Decorators/AttachmentDecorator.php index a73f3e2..506f285 100755 --- a/src/Columns/Decorators/AttachmentDecorator.php +++ b/src/Columns/Decorators/AttachmentDecorator.php @@ -13,11 +13,6 @@ class AttachmentDecorator extends CellDecorator 'height' => 75, ]; - protected function render($row) - { - return \admin\output\staplerImage($row->{$this->name}, $this->style, $this->attributes()); - } - public function setStyle($style) { $this->style = $style; @@ -35,6 +30,7 @@ public function setSize($width, $height) /** * @param bool $rounded + * * @return $this */ public function setRounded(bool $rounded) @@ -44,16 +40,21 @@ public function setRounded(bool $rounded) return $this; } + protected function render($row) + { + return \admin\output\staplerImage($row->{$this->name}, $this->style, $this->attributes()); + } + protected function attributes() { if (!array_key_exists('id', $this->attributes)) { $this->attributes['id'] = $this->name; } - $this->attributes['class'] = "img-responsive"; + $this->attributes['class'] = 'img-responsive'; if ($this->rounded) { - $this->attributes['class'] = "img-circle"; + $this->attributes['class'] = 'img-circle'; } return $this->attributes; diff --git a/src/Columns/Decorators/BooleanDecorator.php b/src/Columns/Decorators/BooleanDecorator.php index cc5dc14..3214b42 100755 --- a/src/Columns/Decorators/BooleanDecorator.php +++ b/src/Columns/Decorators/BooleanDecorator.php @@ -8,4 +8,4 @@ protected function render($row) { return \admin\output\boolean($row->{$this->name}); } -} \ No newline at end of file +} diff --git a/src/Columns/Decorators/CellDecorator.php b/src/Columns/Decorators/CellDecorator.php index b0cb5e4..13f1e61 100755 --- a/src/Columns/Decorators/CellDecorator.php +++ b/src/Columns/Decorators/CellDecorator.php @@ -2,10 +2,10 @@ namespace Terranet\Administrator\Columns\Decorators; +use Terranet\Presentable\PresentableInterface; use function admin\helpers\has_admin_presenter; use function admin\helpers\has_presenter; use function admin\helpers\present; -use Terranet\Presentable\PresentableInterface; abstract class CellDecorator { @@ -37,4 +37,4 @@ protected function present($row, $key) } abstract protected function render($row); -} \ No newline at end of file +} diff --git a/src/Columns/Decorators/DatetimeDecorator.php b/src/Columns/Decorators/DatetimeDecorator.php index 5e3b36c..39a6071 100755 --- a/src/Columns/Decorators/DatetimeDecorator.php +++ b/src/Columns/Decorators/DatetimeDecorator.php @@ -20,9 +20,9 @@ protected function render($row) $value = \admin\helpers\eloquent_attribute($row, $this->name); if ($value instanceof Carbon - && method_exists($value, $method = "to" . str_replace('Type', '', $this->type) . "String") + && method_exists($value, $method = 'to'.str_replace('Type', '', $this->type).'String') ) { - return '' . $value->$method() . ''; + return ''.$value->$method().''; } return $value; diff --git a/src/Columns/Decorators/RankDecorator.php b/src/Columns/Decorators/RankDecorator.php index c0993af..b5dc8ea 100755 --- a/src/Columns/Decorators/RankDecorator.php +++ b/src/Columns/Decorators/RankDecorator.php @@ -8,4 +8,4 @@ protected function render($row) { return \admin\output\rank($this->name, $row->{$this->name}, $row->getKey()); } -} \ No newline at end of file +} diff --git a/src/Columns/Decorators/TextDecorator.php b/src/Columns/Decorators/TextDecorator.php index fd7a769..631a23a 100755 --- a/src/Columns/Decorators/TextDecorator.php +++ b/src/Columns/Decorators/TextDecorator.php @@ -8,18 +8,6 @@ class TextDecorator extends CellDecorator protected $end = '...'; - protected function render($row) - { - return - '' . - str_limit( - strip_tags(\admin\helpers\eloquent_attribute($row, $this->name)), - $this->limit, - $this->end - ) - . ''; - } - public function setLimit($limit) { $this->limit = (int) $limit; @@ -33,4 +21,16 @@ public function setEnd($string) return $this; } + + protected function render($row) + { + return + ''. + str_limit( + strip_tags(\admin\helpers\eloquent_attribute($row, $this->name)), + $this->limit, + $this->end + ) + .''; + } } diff --git a/src/Columns/Element.php b/src/Columns/Element.php index ea5bce5..c740900 100755 --- a/src/Columns/Element.php +++ b/src/Columns/Element.php @@ -24,6 +24,7 @@ class Element extends ElementContainer * Set element display template. * * @param $template + * * @return $this */ public function display($template) @@ -35,18 +36,17 @@ public function display($template) /** * @param Eloquent $eloquent + * * @return mixed */ public function render(Eloquent $eloquent) { - /** - * Fetch value from Eloquent instance. - */ + // Fetch value from Eloquent instance. if (!$this->template) { return $this->fetchValue($eloquent); } - /** + /* * Handle \Illuminate\Contracts\Support\Renderable (view(