Skip to content

Commit

Permalink
Code quality clean up (#4449)
Browse files Browse the repository at this point in the history
Credit to @bennothommo
  • Loading branch information
bennothommo authored and LukeTowers committed Jul 18, 2019
1 parent 9f5ef30 commit ff1db6d
Show file tree
Hide file tree
Showing 33 changed files with 76 additions and 66 deletions.
2 changes: 1 addition & 1 deletion ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ protected function registerAssetBundles()
*/
protected function registerValidator()
{
$this->app->resolving('validator', function($validator) {
$this->app->resolving('validator', function ($validator) {
/*
* Allowed file extensions, as opposed to mime types.
* - extensions: png,jpg,txt
Expand Down
8 changes: 5 additions & 3 deletions classes/CombineAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public static function combine($assets = [], $localPath = null)
* @param string $localPath Prefix all assets with this path (optional)
* @return void
*/
public function combineToFile($assets = [], $destination, $localPath = null)
public function combineToFile($assets, $destination, $localPath = null)
{
// Disable cache always
$this->storagePath = null;
Expand All @@ -212,8 +212,10 @@ public function combineToFile($assets = [], $destination, $localPath = null)
if (substr($localPath, -1) !== '/') {
$localPath = $localPath.'/';
}
$assets = array_map(function($asset) use ($localPath) {
if (substr($asset, 0, 1) === '@') return $asset;
$assets = array_map(function ($asset) use ($localPath) {
if (substr($asset, 0, 1) === '@') {
return $asset;
}
return $localPath.$asset;
}, $assets);
}
Expand Down
12 changes: 9 additions & 3 deletions classes/ComposerManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ public function autoload($vendorPath)
if (file_exists($file = $dir . '/autoload_namespaces.php')) {
$map = require $file;
foreach ($map as $namespace => $path) {
if (isset($this->namespacePool[$namespace])) continue;
if (isset($this->namespacePool[$namespace])) {
continue;
}
$this->loader->set($namespace, $path);
$this->namespacePool[$namespace] = true;
}
Expand All @@ -79,7 +81,9 @@ public function autoload($vendorPath)
if (file_exists($file = $dir . '/autoload_psr4.php')) {
$map = require $file;
foreach ($map as $namespace => $path) {
if (isset($this->psr4Pool[$namespace])) continue;
if (isset($this->psr4Pool[$namespace])) {
continue;
}
$this->loader->setPsr4($namespace, $path);
$this->psr4Pool[$namespace] = true;
}
Expand All @@ -98,7 +102,9 @@ public function autoload($vendorPath)
$includeFiles = require $file;
foreach ($includeFiles as $includeFile) {
$relativeFile = $this->stripVendorDir($includeFile, $vendorPath);
if (isset($this->includeFilesPool[$relativeFile])) continue;
if (isset($this->includeFilesPool[$relativeFile])) {
continue;
}
require $includeFile;
$this->includeFilesPool[$relativeFile] = true;
}
Expand Down
1 change: 0 additions & 1 deletion classes/MailManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ public function renderTemplate($template, $data = [])
$disableAutoInlineCss = false;

if ($template->layout) {

$disableAutoInlineCss = array_get($template->layout->options, 'disable_auto_inline_css', $disableAutoInlineCss);

$html = $this->renderTwig($template->layout->content_html, [
Expand Down
3 changes: 0 additions & 3 deletions classes/MarkupManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ public function registerExtensions($type, array $definitions)
}

foreach ($definitions as $name => $definition) {

switch ($type) {
case self::EXTENSION_TOKEN_PARSER:
$this->$items[$type][] = $definition;
Expand Down Expand Up @@ -227,7 +226,6 @@ public function makeTwigFunctions($functions = [])
}

foreach ($this->listFunctions() as $name => $callable) {

/*
* Handle a wildcard function
*/
Expand Down Expand Up @@ -261,7 +259,6 @@ public function makeTwigFilters($filters = [])
}

foreach ($this->listFilters() as $name => $callable) {

/*
* Handle a wildcard function
*/
Expand Down
3 changes: 2 additions & 1 deletion classes/MediaLibrary.php
Original file line number Diff line number Diff line change
Expand Up @@ -735,8 +735,9 @@ protected function sortItemList(&$itemList, $sortSettings)
*/
protected function filterItemList(&$itemList, $filter)
{
if (!$filter)
if (!$filter) {
return;
}

$result = [];
foreach ($itemList as $item) {
Expand Down
5 changes: 3 additions & 2 deletions classes/PluginBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ public function pluginDetails()

if (!array_key_exists('plugin', $configuration)) {
throw new SystemException(sprintf(
'The plugin configuration file plugin.yaml should contain the "plugin" section: %s.', $thisClass)
);
'The plugin configuration file plugin.yaml should contain the "plugin" section: %s.',
$thisClass
));
}

return $configuration['plugin'];
Expand Down
1 change: 0 additions & 1 deletion classes/SettingsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ protected function filterByContext($items, $context)
{
$filteredItems = [];
foreach ($items as $categoryName => $category) {

$filteredCategory = [];
foreach ($category as $item) {
$itemContext = is_array($item->context) ? $item->context : [$item->context];
Expand Down
5 changes: 3 additions & 2 deletions classes/UpdateManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,6 @@ public function updatePlugin($name)
$this->versionManager->resetNotes()->setNotesOutput($this->notesOutput);

if ($this->versionManager->updatePlugin($plugin) !== false) {

foreach ($this->versionManager->getNotes() as $note) {
$this->note($note);
}
Expand Down Expand Up @@ -680,7 +679,9 @@ public function requestProductDetails($codes, $type = null)
$requestedDetails = array_intersect_key($this->productCache[$type], array_flip($codes));

foreach ($requestedDetails as $detail) {
if ($detail === -1) continue;
if ($detail === -1) {
continue;
}
$result[] = $detail;
}

Expand Down
3 changes: 2 additions & 1 deletion console/OctoberInstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ protected function setupAdvancedValues()
$this->writeToConfig('app', ['debug' => $debug]);
}

protected function askToInstallPlugins() {
protected function askToInstallPlugins()
{
$chosenToInstall = [];
if ($this->confirm('Install the October.Drivers plugin?', false)) {
$chosenToInstall[] = 'October.Drivers';
Expand Down
19 changes: 11 additions & 8 deletions console/OctoberUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ protected function utilCompileAssets($type = null)
$combiner = CombineAssets::instance();
$bundles = $combiner->getBundles($type);

if (!$bundles){
if (!$bundles) {
$this->comment('Nothing to compile!');
return;
}
Expand Down Expand Up @@ -198,7 +198,6 @@ protected function utilCompileLang()
$stub = base_path() . '/modules/system/assets/js/lang/lang.stub';

foreach ($locales as $locale) {

/*
* Generate messages
*/
Expand All @@ -209,7 +208,7 @@ protected function utilCompileLang()
if (File::isFile($srcPath) && $fallbackPath != $srcPath) {
$messages = array_replace_recursive($messages, require $srcPath);
}

/*
* Load possible replacements from /lang
*/
Expand Down Expand Up @@ -314,7 +313,10 @@ protected function utilGitPull()
{
foreach (File::directories(plugins_path()) as $authorDir) {
foreach (File::directories($authorDir) as $pluginDir) {
if (!File::isDirectory($pluginDir.'/.git')) continue;
if (!File::isDirectory($pluginDir.'/.git')) {
continue;
}

$exec = 'cd ' . $pluginDir . ' && ';
$exec .= 'git pull 2>&1';
echo 'Updating plugin: '. basename(dirname($pluginDir)) .'.'. basename($pluginDir) . PHP_EOL;
Expand All @@ -323,7 +325,10 @@ protected function utilGitPull()
}

foreach (File::directories(themes_path()) as $themeDir) {
if (!File::isDirectory($themeDir.'/.git')) continue;
if (!File::isDirectory($themeDir.'/.git')) {
continue;
}

$exec = 'cd ' . $themeDir . ' && ';
$exec .= 'git pull 2>&1';
echo 'Updating theme: '. basename($themeDir) . PHP_EOL;
Expand All @@ -335,7 +340,7 @@ protected function utilSetProject()
{
$projectId = $this->option('projectId');

if (empty($projectId)){
if (empty($projectId)) {
$this->error("No projectId defined, use --projectId=<id> to set a projectId");
return;
}
Expand All @@ -348,7 +353,5 @@ protected function utilSetProject()
'system::project.name' => $result['name'],
'system::project.owner' => $result['owner'],
]);

}

}
2 changes: 1 addition & 1 deletion console/PluginList.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function handle()
$allPlugins = PluginVersion::all();
$pluginsCount = count($allPlugins);

if ($pluginsCount <= 0 ) {
if ($pluginsCount <= 0) {
$this->info('No plugin found');
return;
}
Expand Down
1 change: 0 additions & 1 deletion console/ThemeList.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public function handle()
}

if ($this->option('include-marketplace')) {

// @todo List everything in the marketplace - not just popular.

$popularThemes = $updateManager->requestPopularProducts('theme');
Expand Down
2 changes: 1 addition & 1 deletion console/ThemeSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public function handle()
}

// Confirm with the user
if (!$this->confirmToProceed(sprintf('This will OVERWRITE the %s provided paths in "themes/%s" on the %s with content from the %s', count($validPaths), $themeName, $target, $source), function () { return true; })) {
if (!$this->confirmToProceed(sprintf('This will OVERWRITE the %s provided paths in "themes/%s" on the %s with content from the %s', count($validPaths), $themeName, $target, $source), true)) {
return;
}

Expand Down
5 changes: 3 additions & 2 deletions controllers/EventLogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ public function index_onEmptyLog()
public function index_onDelete()
{
if (($checkedIds = post('checked')) && is_array($checkedIds) && count($checkedIds)) {

foreach ($checkedIds as $recordId) {
if (!$record = EventLog::find($recordId)) continue;
if (!$record = EventLog::find($recordId)) {
continue;
}
$record->delete();
}

Expand Down
5 changes: 3 additions & 2 deletions controllers/RequestLogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ public function index_onEmptyLog()
public function index_onDelete()
{
if (($checkedIds = post('checked')) && is_array($checkedIds) && count($checkedIds)) {

foreach ($checkedIds as $recordId) {
if (!$record = RequestLog::find($recordId)) continue;
if (!$record = RequestLog::find($recordId)) {
continue;
}
$record->delete();
}

Expand Down
18 changes: 12 additions & 6 deletions controllers/Updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,15 @@ protected function getPluginVersionFile($path, $filename)
}

//Filter out update scripts
$details = array_filter($details, function($string) use ($path) {
$details = array_filter($details, function ($string) use ($path) {
return !preg_match('/^[a-z_\-0-9]*\.php$/i', $string) || !File::exists($path . '/updates/' . $string);
});

$contents[$version] = $details;
}
}
catch (Exception $ex) {}
catch (Exception $ex) {
}

uksort($contents, function ($a, $b) {
return version_compare($b, $a);
Expand All @@ -209,7 +210,9 @@ protected function getPluginMarkdownFile($path, $filenames)
{
$contents = null;
foreach ($filenames as $file) {
if (!File::exists($path . '/'.$file)) continue;
if (!File::exists($path . '/'.$file)) {
continue;
}

$contents = File::get($path . '/'.$file);

Expand Down Expand Up @@ -369,7 +372,9 @@ protected function processImportantUpdates($result)
$coreImportant = false;

foreach (array_get($result, 'core.updates', []) as $build => $description) {
if (strpos($description, '!!!') === false) continue;
if (strpos($description, '!!!') === false) {
continue;
}

$detailsUrl = '//octobercms.com/support/articles/release-notes';
$description = str_replace('!!!', '', $description);
Expand All @@ -387,7 +392,9 @@ protected function processImportantUpdates($result)
$isImportant = false;

foreach (array_get($plugin, 'updates', []) as $version => $description) {
if (strpos($description, '!!!') === false) continue;
if (strpos($description, '!!!') === false) {
continue;
}

$isImportant = $hasImportantUpdates = true;
$detailsUrl = Backend::url('system/updates/details/'.PluginVersion::makeSlug($code).'/upgrades').'?fetch=1';
Expand Down Expand Up @@ -910,7 +917,6 @@ public function onInstallTheme()
public function onRemoveTheme()
{
if ($themeCode = post('code')) {

ThemeManager::instance()->deleteTheme($themeCode);

Flash::success(trans('cms::lang.theme.delete_theme_success'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public function up()
$layout->content_text = preg_replace("/({{\s*message\s*[|]raw\s*}})/i", "{{ content|raw }}", $layout->content_text);
$layout->forceSave();
}
catch (Exception $ex) {}
catch (Exception $ex) {
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ public function up()
$table->text('options')->nullable()->after('is_locked');
});
}

public function down()
{
Schema::table('system_mail_layouts', function (Blueprint $table) {
$table->dropColumn('options');
$table->dropColumn('options');
});
}
}
4 changes: 2 additions & 2 deletions helpers/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public static function makeCarbon($value, $throwException = true)
else {
try {
$value = Carbon::parse($value);
} catch (Exception $ex) {}
} catch (Exception $ex) {
}
}

if (!$value instanceof Carbon && $throwException) {
Expand Down Expand Up @@ -131,5 +132,4 @@ public static function momentFormat($format)

return strtr($format, $replacements);
}

}
4 changes: 2 additions & 2 deletions lang/en/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
],
'scopes' => [
'apply_button_text' => 'Apply',
'clear_button_text' => 'Clear'
],
'clear_button_text' => 'Clear'
],
'dates' => [
'all' => 'all',
'filter_button_text' => 'Filter',
Expand Down
Loading

0 comments on commit ff1db6d

Please sign in to comment.