Skip to content

Commit

Permalink
PHPCS autofixed + correct use ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
dakota committed Oct 15, 2019
1 parent 4c6d6e9 commit 06ba557
Show file tree
Hide file tree
Showing 27 changed files with 326 additions and 251 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

use Migrations\AbstractMigration;

class SettingsInitialMigration extends AbstractMigration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

use Migrations\AbstractMigration;

class EnlargeLanguagesFields extends AbstractMigration
Expand Down Expand Up @@ -26,5 +27,4 @@ public function down()
->removeIndexByName('ix_languages_locale')
->save();
}

}
3 changes: 1 addition & 2 deletions config/Seeds/LanguagesSeed.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

use Phinx\Seed\AbstractSeed;
use Cake\I18n\I18n;
use Phinx\Seed\AbstractSeed;

class LanguagesSeed extends AbstractSeed
{
Expand Down Expand Up @@ -64,5 +64,4 @@ public function run()

$Table->insert($records)->save();
}

}
1 change: 0 additions & 1 deletion config/Seeds/SettingsSeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,5 +334,4 @@ public function run()
$Table = $this->table('settings');
$Table->insert($this->records)->save();
}

}
1 change: 0 additions & 1 deletion config/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

use Cake\Core\Configure;
use Cake\Cache\Cache;
use Croogo\Core\Croogo;

Configure::write(
Expand Down
37 changes: 19 additions & 18 deletions src/Configure/Engine/DatabaseConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@
use Cake\Cache\Cache;
use Cake\Core\Configure\ConfigEngineInterface;
use Cake\Log\Log;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
use Cake\Utility\Hash;
use Croogo\Settings\Model\Entity\Setting;
use function Croogo\Core\timerStart;
use function Croogo\Core\timerStop;

class DatabaseConfig implements ConfigEngineInterface
{
/**
* Read method is used for reading configuration information from sources.
* These sources can either be static resources like files, or dynamic ones like
* a database, or other datasource.
*
* @param string $key Key to read.
* @return array An array of data to merge into the runtime configuration
*/
/**
* Read method is used for reading configuration information from sources.
* These sources can either be static resources like files, or dynamic ones like
* a database, or other datasource.
*
* @param string $key Key to read.
* @return array An array of data to merge into the runtime configuration
*/
public function read($key)
{
\Croogo\Core\timerStart('Loading settings from database');
timerStart('Loading settings from database');

$values = Cache::remember('configure-settings-' . $key, function () use ($key) {
$settings = TableRegistry::get('Croogo/Settings.Settings')->find('list', [
Expand All @@ -48,18 +49,18 @@ public function read($key)
return $settings;
}, 'cached_settings');

\Croogo\Core\timerStop('Loading settings from database');
timerStop('Loading settings from database');

return $values;
}

/**
* Dumps the configure data into source.
*
* @param string $key The identifier to write to.
* @param array $data The data to dump.
* @return bool True on success or false on failure.
*/
/**
* Dumps the configure data into source.
*
* @param string $key The identifier to write to.
* @param array $data The data to dump.
* @return bool True on success or false on failure.
*/
public function dump($key, array $data)
{
Log::debug($key);
Expand Down
3 changes: 1 addition & 2 deletions src/Controller/Admin/CachesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Croogo\Settings\Controller\Admin;

use Cake\Cache\Cache;
use Croogo\Core\Event\EventManager;

/**
* Caches Controller
Expand Down Expand Up @@ -48,7 +47,7 @@ public function clear()
} else {
$this->Flash->warning(__d('croogo', 'Failed clearing cache'));
}

return $this->redirect($this->getRequest()->referer());
}

}
20 changes: 10 additions & 10 deletions src/Controller/Admin/LanguagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Croogo\Settings\Controller\Admin;

use Cake\Event\Event;
use Croogo\Core\Event\EventManager;

/**
* Languages Controller
Expand Down Expand Up @@ -38,14 +37,14 @@ public function initialize()
$this->_setupPrg();
}

/**
* Admin select
*
* @param int $id
* @param string $modelAlias
* @return void
* @access public
*/
/**
* Admin select
*
* @param int $id
* @param string $modelAlias
* @return void
* @access public
*/
public function select()
{
$id = $this->getRequest()->getQuery('id');
Expand All @@ -67,12 +66,13 @@ public function select()

public function index()
{
$this->Crud->on('beforePaginate', function(Event $e) {
$this->Crud->on('beforePaginate', function (Event $e) {
if (empty($this->getRequest()->getQuery('sort'))) {
$e->getSubject()->query
->orderDesc('status');
}
});

return $this->Crud->execute();
}
}
54 changes: 28 additions & 26 deletions src/Controller/Admin/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Cake\Event\Event;
use Cake\Utility\Inflector;
use Exception;

/**
* Settings Controller
Expand Down Expand Up @@ -38,18 +39,17 @@ public function beforeCrudRedirect(Event $event)
}
}

/**
* Admin prefix
*
* @param string $prefix
* @return void
* @access public
*/
/**
* Admin prefix
*
* @param string $prefix
* @return void
* @access public
*/
public function prefix($prefix = null)
{
if ($this->getRequest()->is('post')) {
try {

foreach ($this->getRequest()->getData() as $inputName => $value) {
$id = str_replace('setting-', '', $inputName);
if ($id == '_apply') {
Expand All @@ -70,7 +70,7 @@ public function prefix($prefix = null)
}

$this->Flash->success(__d('croogo', 'Settings updated successfully'));
} catch (\Exception $e) {
} catch (Exception $e) {
$this->Flash->error(__d('croogo', 'Settings cannot be updated: ' . $e->getMessage()));
}

Expand Down Expand Up @@ -103,7 +103,7 @@ protected function _handleUpload($setting, $value)

$contentType = mime_content_type($value['tmp_name']);
if (substr($contentType, 0, 5) !== 'image') {
throw new \Exception('Invalid file type');
throw new Exception('Invalid file type');
}

$dotPosition = strripos($name, '.');
Expand All @@ -120,17 +120,18 @@ protected function _handleUpload($setting, $value)
$targetFile = WWW_ROOT . $relativePath;
move_uploaded_file($value['tmp_name'], $targetFile);
$value = str_replace('\\', '/', $relativePath);

return $value;
}

/**
* Admin moveup
*
* @param int $id
* @param int $step
* @return void
* @access public
*/
/**
* Admin moveup
*
* @param int $id
* @param int $step
* @return void
* @access public
*/
public function moveup($id, $step = 1)
{
if ($this->Setting->moveUp($id, $step)) {
Expand All @@ -147,17 +148,18 @@ public function moveup($id, $step = 1)
'action' => 'index'
];
}

return $this->redirect($redirect);
}

/**
* Admin moveup
*
* @param int $id
* @param int $step
* @return void
* @access public
*/
/**
* Admin moveup
*
* @param int $id
* @param int $step
* @return void
* @access public
*/
public function movedown($id, $step = 1)
{
if ($this->Setting->moveDown($id, $step)) {
Expand Down
12 changes: 6 additions & 6 deletions src/Controller/Component/SettingsComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
class SettingsComponent extends Component
{

/**
* @var Controller
*/
/**
* @var Controller
*/
protected $_controller;

/**
* startup
*/
/**
* startup
*/
public function startup(Event $event)
{
$this->_controller = $event->getSubject();
Expand Down
6 changes: 3 additions & 3 deletions src/Event/SettingsEventHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
class SettingsEventHandler implements EventListenerInterface
{

/**
* implementedEvents
*/
/**
* implementedEvents
*/
public function implementedEvents()
{
return [];
Expand Down
2 changes: 0 additions & 2 deletions src/Model/Entity/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Croogo\Settings\Model\Entity;

use Cake\Core\App;
use Cake\ORM\Entity;

class Language extends Entity
Expand All @@ -12,5 +11,4 @@ protected function _getLabel()
{
return $this->_properties['native'] ?: $this->_properties['title'];
}

}
1 change: 1 addition & 0 deletions src/Model/Entity/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ protected function _getOptions()
return [];
}
$class = new $className();

return $class();
} elseif (!empty($this->params['options'])) {
return json_decode($this->params['options'], true);
Expand Down
18 changes: 11 additions & 7 deletions src/Model/Table/LanguagesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Croogo\Settings\Model\Table;

use Cake\ORM\Entity;
use Cake\ORM\Query;
use Cake\ORM\RulesChecker;
use Cake\Validation\Validator;
Expand All @@ -21,9 +20,9 @@
class LanguagesTable extends CroogoTable
{

/**
* Initialize
*/
/**
* Initialize
*/
public function initialize(array $config)
{
$this->addBehavior('Croogo/Core.Trackable');
Expand All @@ -50,18 +49,22 @@ public function validationDefault(Validator $validator)
->notBlank('native', __d('croogo', 'Native cannot be empty.'))
->notBlank('alias', __d('croogo', 'Alias cannot be empty.'))
->notBlank('locale', __d('croogo', 'Locale cannot be empty.'));

return $validator;
}

public function buildRules(RulesChecker $rules)
{
$rules
->add($rules->isUnique(['locale'],
->add($rules->isUnique(
['locale'],
__d('croogo', 'That locale is already taken')
))
->add($rules->isUnique( ['alias'],
->add($rules->isUnique(
['alias'],
__d('croogo', 'That alias is already taken')
));

return $rules;
}

Expand All @@ -75,9 +78,10 @@ public function findActive(Query $query)
foreach ($results as $row) {
$formatted[$row->alias] = ['locale' => $row->locale];
}

return $formatted;
});

return $query;
}

}
Loading

0 comments on commit 06ba557

Please sign in to comment.