Major code formate to try and set a standard. #201

Closed
Llewellyn wants to merge 3 commits from staging into master
pull from: staging
11 changed files with 107 additions and 112 deletions

No files matched your search

+3 -3
View File
@@ -144,13 +144,13 @@ TODO
+ *Author*: [Llewellyn van der Merwe](mailto:joomla@vdm.io)
+ *Name*: [Component Builder](https://git.vdm.dev/joomla/Component-Builder)
+ *First Build*: 30th April, 2015
+ *Last Build*: 2nd May, 2023
+ *Last Build*: 22nd May, 2023
+ *Version*: 3.1.24
+ *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved.
+ *License*: GNU General Public License version 2 or later; see LICENSE.txt
+ *Line count*: **557762**
+ *Line count*: **559431**
+ *Field count*: **2041**
+ *File count*: **3930**
+ *File count*: **3934**
+ *Folder count*: **432**
> This **component** was build with a [Joomla](https://extensions.joomla.org/extension/component-builder/) [Automated Component Builder](https://www.joomlacomponentbuilder.com).
+3 -3
View File
@@ -144,13 +144,13 @@ TODO
+ *Author*: [Llewellyn van der Merwe](mailto:joomla@vdm.io)
+ *Name*: [Component Builder](https://git.vdm.dev/joomla/Component-Builder)
+ *First Build*: 30th April, 2015
+ *Last Build*: 2nd May, 2023
+ *Last Build*: 22nd May, 2023
+ *Version*: 3.1.24
+ *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved.
+ *License*: GNU General Public License version 2 or later; see LICENSE.txt
+ *Line count*: **557762**
+ *Line count*: **559431**
+ *Field count*: **2041**
+ *File count*: **3930**
+ *File count*: **3934**
+ *Folder count*: **432**
> This **component** was build with a [Joomla](https://extensions.joomla.org/extension/component-builder/) [Automated Component Builder](https://www.joomlacomponentbuilder.com).
+2 -2
View File
@@ -1325,7 +1325,7 @@ class Fields extends Structure
}
}
// fix the permissions field "title" issue gh-629
// check if the the title is not already set
// check if the title is not already set
if (!CFactory::_('Registry')->isString('builder.field_names.' . $nameSingleCode . '.title')
&& $this->hasPermissionsSet($view, $nameSingleCode))
{
@@ -3982,7 +3982,7 @@ class Fields extends Structure
. $field['alignment'] . '.'
. $field['order_edit'], $name);
}
// check if default fields were over written
// check if default fields were overwritten
if (in_array($name, $default_fields))
{
// just to eliminate
+18 -27
View File
@@ -4972,7 +4972,7 @@ class Interpretation extends Fields
public function setAdminViewDisplayMethod($nameListCode)
{
$script = '';
// add the the new filter methods for the search toolbar above the list view (2 = topbar)
// add the new filter methods for the search toolbar above the list view (2 = topbar)
if (CFactory::_('Registry')->
get('builder.admin_filter_type.' . $nameListCode, 1) == 2)
{
@@ -10052,6 +10052,7 @@ class Interpretation extends Fields
{
$default = $data['other'];
}
// to get just null value add EMPTY to other value.
if ($default === 'EMPTY')
{
$default = $data['null_switch'];
@@ -10062,42 +10063,32 @@ class Interpretation extends Fields
$default = $data['null_switch'] . ' DEFAULT '
. $default;
}
elseif ($default == 0 || $default)
elseif (is_numeric($default))
{
if (is_numeric($default))
{
$default = $data['null_switch'] . " DEFAULT "
. $default;
}
else
{
$default = $data['null_switch'] . " DEFAULT '"
. $default . "'";
}
}
elseif ($data['null_switch'] === 'NULL')
{
$default = "DEFAULT NULL";
$default = $data['null_switch'] . " DEFAULT "
. $default;
}
else
{
$default = $data['null_switch'];
$default = $data['null_switch'] . " DEFAULT '"
. $default . "'";
}
// set the lenght
$lenght = '';
// set the length (lenght) <-- TYPO :: LVDM :: DON'T TOUCH
$length = '';
if (isset($data['lenght']) && $data['lenght'] === 'Other'
&& isset($data['lenght_other'])
&& $data['lenght_other'] > 0)
{
$lenght = '(' . $data['lenght_other'] . ')';
$length = '(' . $data['lenght_other'] . ')';
}
elseif (isset($data['lenght']) && $data['lenght'] > 0)
{
$lenght = '(' . $data['lenght'] . ')';
$length = '(' . $data['lenght'] . ')';
}
// set the field to db
$db_ .= PHP_EOL . Indent::_(1) . "`" . $field . "` "
. $data['type'] . $lenght . " " . $default . ",";
. $data['type'] . $length . " " . $default . ",";
// check if this a new field that should be added via SQL update
if (CFactory::_('Registry')->
get('builder.add_sql.field.' . $view . '.' . $data['ID'], null))
@@ -10105,10 +10096,10 @@ class Interpretation extends Fields
// to soon....
// $key_ = "ALTERTABLE`#__" . $component . "_" . $view . "`ADDCOLUMNIFNOTEXISTS`" . $field . "`";
// $value_ = "ALTER TABLE `#__" . $component . "_" . $view . "` ADD COLUMN IF NOT EXISTS `" . $field . "` " . $data['type']
// . $lenght . " " . $default . " AFTER `" . $last_name . "`;";
// . length . " " . $default . " AFTER `" . $last_name . "`;";
$key_ = "ALTERTABLE`#__" . $component . "_" . $view . "`ADD`" . $field . "`";
$value_ = "ALTER TABLE `#__" . $component . "_" . $view . "` ADD `" . $field . "` " . $data['type']
. $lenght . " " . $default . " AFTER `" . $last_name . "`;";
. $length . " " . $default . " AFTER `" . $last_name . "`;";
CFactory::_('Builder.Update.Mysql')->set($key_, $value_);
}
@@ -10131,7 +10122,7 @@ class Interpretation extends Fields
$key_ = "ALTERTABLE`#__" . $component . "_" . $view . "`CHANGE`" . $oldName . "``"
. $field . "`";
$value_ = "ALTER TABLE `#__" . $component . "_" . $view . "` CHANGE `" . $oldName . "` `"
. $field . "` " . $data['type'] . $lenght . " " . $default . ";";
. $field . "` " . $data['type'] . $length . " " . $default . ";";
CFactory::_('Builder.Update.Mysql')->set($key_, $value_);
}
@@ -11129,7 +11120,7 @@ class Interpretation extends Fields
$body .= PHP_EOL . Indent::_(1) . "?>";
$body .= PHP_EOL . Indent::_(1)
. '<tr class="row<?php echo $i % 2; ?>">';
// only load if not over written
// only load if not overwritten
if (!CFactory::_('Registry')->isString('builder.field_names.' . $nameSingleCode . '.ordering'))
{
$body .= PHP_EOL . Indent::_(2)
@@ -11236,7 +11227,7 @@ class Interpretation extends Fields
$item, $nameSingleCode, $nameListCode, $itemClass,
$doNotEscape, $coreLoad, $core
);
// check if buttons was aready added
// check if buttons was already added
if ($firstTimeBeingAdded) // TODO we must improve this to allow more items to be targeted instead of just the first item :)
{
// get custom admin view buttons
+1 -1
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="4" method="upgrade">
<name>COM_COMPONENTBUILDER</name>
<creationDate>2nd May, 2023</creationDate>
<creationDate>22nd May, 2023</creationDate>
<author>Llewellyn van der Merwe</author>
<authorEmail>joomla@vdm.io</authorEmail>
<authorUrl>https://dev.vdm.io</authorUrl>
@@ -92,7 +92,7 @@ class Adminviews
$item->addadmin_views, function ($a, $b) {
if ($a['order'] != 0 && $b['order'] != 0)
{
return $a['order'] - $b['order'];
return $a['order'] <=> $b['order'];
}
elseif ($b['order'] != 0 && $a['order'] == 0)
{
@@ -204,7 +204,7 @@ class Fields
{
if ($a['order_list'] != 0 && $b['order_list'] != 0)
{
return $a['order_list'] - $b['order_list'];
return $a['order_list'] <=> $b['order_list'];
}
elseif ($b['order_list'] != 0 && $a['order_list'] == 0)
{
@@ -212,7 +212,7 @@ class Fields
}
elseif ($a['order_list'] != 0 && $b['order_list'] == 0)
{
return 0;
return -1;
}
return 1;
@@ -69,6 +69,14 @@ class Power implements PowerInterface
**/
public array $superpowers = [];
/**
* Old super powers found in the local repos
*
* @var array
* @since 3.2.0
**/
public array $old_superpowers = [];
/**
* The url to the power, if there is an error.
*
@@ -232,9 +232,18 @@ class Infusion
array(&$context, &$path, &$key, &$powers)
);
// we add and all missing powers
if (isset($this->power->old_superpowers[$path]))
{
$this->mergePowers($powers, $this->power->old_superpowers[$path]);
}
// POWERREADME
$this->content->set_($key, 'POWERREADME', $this->reposreadme->get($powers));
// sort all powers
$this->sortPowers($powers);
// POWERINDEX
$this->content->set_($key, 'POWERINDEX', $this->index($powers));
@@ -247,6 +256,34 @@ class Infusion
}
}
/**
* Merge the old missing powers found in local repository back into the index
*
* @return void
* @since 3.2.0
*/
private function mergePowers(array &$powers, array &$old)
{
foreach ($old as $guid => $values)
{
if (!isset($powers[$guid]))
{
$powers[$guid] = $values;
}
}
}
/**
* Sort Powers
*
* @return void
* @since 3.2.0
*/
private function sortPowers(array &$powers)
{
ksort($powers, SORT_STRING);
}
/**
* Set the Powers code
*
@@ -123,18 +123,13 @@ class Readme
$classes = [];
foreach ($powers as $guid => $power)
{
$power_object = $this->power->get($guid);
if (isset($power_object->parsed_class_code) && is_array($power_object->parsed_class_code))
{
// add to the sort bucket
$classes[] = [
'namespace' => $power['namespace'],
'type' => $power['type'],
'name' => $power['name'],
'link' => $this->indexLinkPower($power),
'diagram' => $this->plantuml->classBasicDiagram($power, $power_object->parsed_class_code)
];
}
// add to the sort bucket
$classes[] = [
'namespace' => $power['namespace'],
'type' => $power['type'],
'name' => $power['name'],
'link' => $this->indexLinkPower($power)
];
}
return $this->readmeModel($classes);
@@ -152,11 +147,7 @@ class Readme
{
$this->sortClasses($classes, $this->defineTypeOrder());
$result = $this->generateIndex($classes);
$diagram_bucket = $this->generateDiagramBucket($classes);
return $result . $diagram_bucket;
return $this->generateIndex($classes);
}
/**
@@ -187,40 +178,6 @@ class Readme
return $result;
}
/**
* Generate the diagram bucket string for classes
*
* @param array $classes The sorted classes
*
* @return string The diagram bucket string
*/
private function generateDiagramBucket(array &$classes): string
{
$diagram_bucket = "\n\n# Class Diagrams\n";
$current_namespace = null;
$diagrams = '';
foreach ($classes as $class)
{
if ($class['namespace'] !== $current_namespace)
{
if ($current_namespace !== null)
{
$diagram_bucket .= $this->generateNamespaceDiagram($current_namespace, $diagrams);
}
$current_namespace = $class['namespace'];
$diagrams = '';
}
$diagrams .= $class['diagram'];
}
// Add the last namespace diagram
$diagram_bucket .= $this->generateNamespaceDiagram($current_namespace, $diagrams);
return $diagram_bucket;
}
/**
* Define the order of types for sorting purposes
*
@@ -301,7 +258,7 @@ class Readme
*/
private function compareType(array $a, array $b, array $typeOrder): int
{
return $typeOrder[$a['type']] - $typeOrder[$b['type']];
return $typeOrder[$a['type']] <=> $typeOrder[$b['type']];
}
/**
@@ -318,24 +275,6 @@ class Readme
return strcmp($a['name'], $b['name']);
}
/**
* Generate a namespace diagram string
*
* @param string $current_namespace The current namespace
* @param string $diagrams The diagrams for the namespace
*
* @return string The namespace diagram string
*/
private function generateNamespaceDiagram(string $current_namespace, string $diagrams): string
{
$namespace_title = str_replace('\\', ' ', $current_namespace);
$diagram_code = "\n## {$namespace_title}\n> namespace {$current_namespace}\n";
$diagram_code .= "```uml\n@startuml\n\n" .
$this->plantuml->namespaceDiagram($current_namespace, $diagrams) . "\n\n@enduml\n```\n";
return $diagram_code;
}
/**
* Build the Link to the power in this repository
*
@@ -403,7 +342,6 @@ class Readme
private function linkPowerSPK(array &$power): string
{
return $power['spk'];
}
}
}
@@ -28,6 +28,8 @@ use VDM\Joomla\Componentbuilder\Compiler\Utilities\Files;
use VDM\Joomla\Utilities\ObjectHelper;
use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Utilities\JsonHelper;
use VDM\Joomla\Utilities\FileHelper;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Placefix;
@@ -372,6 +374,9 @@ class Structure
{
foreach ($this->power->superpowers as $path => $powers)
{
// get existing files
$this->loadExistingSuperPower($path);
// create the path if it does not exist
$this->folder->create($path, false);
@@ -424,6 +429,22 @@ class Structure
}
}
}
/**
* Set the super power file paths
*
* @param string $repository The super power repository
*
* @return void
* @since 3.2.0
*/
private function loadExistingSuperPower(string $repository)
{
if (($content = FileHelper::getContent($repository . '/super-powers.json', null)) !== null &&
JsonHelper::check($content))
{
$this->power->old_superpowers[$repository] = json_decode($content, true);
}
}
}