Skip to content

Commit

Permalink
Jet Core
Browse files Browse the repository at this point in the history
------------
* ORM DataModel: Bug fix: Some definitions are not mandatory anymore when the class is abstract
* Minor code quality improvements
  • Loading branch information
mirekmarek committed Sep 12, 2024
1 parent 73ac0c3 commit c2ebf58
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 51 deletions.
18 changes: 2 additions & 16 deletions library/Jet/DataListing/Traits/Columns.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,7 @@ public function getVisibleColumns(): array
}

uasort($columns, function( DataListing_Column $a, DataListing_Column $b ) : int {
if($a->getIndex()<$b->getIndex()) {
return -1;
}
if($a->getIndex()>$b->getIndex()) {
return 1;
}

return 0;
return $a->getIndex() <=> $b->getIndex();
});

return $columns;
Expand All @@ -85,14 +78,7 @@ public function getNotVisibleColumns(): array
}

uasort($columns, function( DataListing_Column $a, DataListing_Column $b ) : int {
if($a->getIndex()<$b->getIndex()) {
return -1;
}
if($a->getIndex()>$b->getIndex()) {
return 1;
}

return 0;
return $a->getIndex() <=> $b->getIndex();
});

return $columns;
Expand Down
24 changes: 16 additions & 8 deletions library/Jet/DataModel/Definition/Model/Related.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ protected function _initParents(): void
$parent_model_class = $this->getClassArgument( 'parent_model_class' );

if( !$parent_model_class ) {
if($this->class_reflection->isAbstract()) {
return;
}

throw new DataModel_Exception(
$this->class_name . ' #[DataModel_Definition(parent_model_class: SomeParent::class)] attribute is not defined ',
DataModel_Exception::CODE_DEFINITION_NONSENSE
Expand Down Expand Up @@ -146,10 +150,12 @@ protected function _initProperties(): void
}

if( !in_array( $property_name, $main_id_relation_defined ) ) {
throw new DataModel_Exception(
'Class: \'' . $this->class_name . '\' Main model relation property is missing! Please declare property with this attribute: #[DataModel_Definition(related_to: \'main.' . $property_name . '\')] ',
DataModel_Exception::CODE_DEFINITION_NONSENSE
);
if(!$this->class_reflection->isAbstract()) {
throw new DataModel_Exception(
'Class: \'' . $this->class_name . '\' Main model relation property is missing! Please declare property with this attribute: #[DataModel_Definition(related_to: \'main.' . $property_name . '\')] ',
DataModel_Exception::CODE_DEFINITION_NONSENSE
);
}
}
}

Expand All @@ -166,10 +172,12 @@ protected function _initProperties(): void
}

if( !in_array( $property_name, $parent_id_relation_defined ) ) {
throw new DataModel_Exception(
'Class: \'' . $this->class_name . '\' parent model relation property is missing! Please declare property with this attribute: #[DataModel_Definition(related_to:\'parent.' . $property_name . '\')]',
DataModel_Exception::CODE_DEFINITION_NONSENSE
);
if(!$this->class_reflection->isAbstract()) {
throw new DataModel_Exception(
'Class: \'' . $this->class_name . '\' parent model relation property is missing! Please declare property with this attribute: #[DataModel_Definition(related_to:\'parent.' . $property_name . '\')]',
DataModel_Exception::CODE_DEFINITION_NONSENSE
);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/Jet/DataModel/Trait/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function delete(): void
if(
$v instanceof DataModel_Related &&
$v->getIsSaved()
) {
) {
$v->delete();
}
}
Expand Down
10 changes: 6 additions & 4 deletions library/Jet/Locale.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php /** @noinspection PhpMultipleClassDeclarationsInspection */
<?php

/**
*
Expand Down Expand Up @@ -325,7 +325,7 @@ class Locale extends BaseObject
*
* @param null|Locale $in_locale (optional, default: current locale)
*
* @return array
* @return static[]
*/
public static function getAllLocalesList( null|Locale $in_locale = null ) : array
{
Expand Down Expand Up @@ -594,7 +594,8 @@ public function formatTime( ?Data_DateTime $date_and_time, int $time_format = se
*/
public function formatInt( int $number ): string
{


/** @noinspection PhpExpectedValuesShouldBeUsedInspection */
$f = new PHP_NumberFormatter( $this->locale, PHP_NumberFormatter::DECIMAL );

$f->setAttribute( PHP_NumberFormatter::MIN_FRACTION_DIGITS, 0 );
Expand All @@ -613,7 +614,8 @@ public function formatInt( int $number ): string
*/
public function formatFloat( float $number, int $min_fraction_digits = 0, int $max_fraction_digits = 2 ): string
{


/** @noinspection PhpExpectedValuesShouldBeUsedInspection */
$f = new PHP_NumberFormatter( $this->locale, PHP_NumberFormatter::DECIMAL );

$f->setAttribute( PHP_NumberFormatter::MIN_FRACTION_DIGITS, $min_fraction_digits );
Expand Down
10 changes: 2 additions & 8 deletions library/Jet/MVC/Layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,7 @@ protected function handlePositions( string &$result ): void
}

uasort( $this->output_parts, function( MVC_Layout_OutputPart $a, MVC_Layout_OutputPart $b ) {
$a_o = $a->getPositionOrder();
$b_o = $b->getPositionOrder();

if( $a_o == $b_o ) {
return 0;
}
return ($a_o < $b_o) ? -1 : 1;
return $a->getPositionOrder() <=> $b->getPositionOrder();
} );


Expand Down Expand Up @@ -626,7 +620,7 @@ public function removePostprocessor( string $id ) : void
}
}

public function performPostprocess( string $output ) : string
public function performPostprocess( $output ) : string
{
foreach($this->postprocessors as $postprocessor) {
$output = $postprocessor->process( $output );
Expand Down
9 changes: 1 addition & 8 deletions library/Jet/MVC/Page/Trait/Tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,7 @@ public function getChildren(): array
uasort(
$this->__children,
function( MVC_Page $a, MVC_Page $b ) {
$a_order = $a->getOrder();
$b_order = $b->getOrder();

if( $a_order == $b_order ) {
return 0;
}

return ($a_order < $b_order) ? -1 : 1;
return $a->getOrder() <=> $b->getOrder();
}
);

Expand Down
8 changes: 2 additions & 6 deletions library/Jet/Navigation/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,8 @@ function( $a, $b ) {
* @var Navigation_Menu|Navigation_Menu_Item $a
* @var Navigation_Menu|Navigation_Menu_Item $b
*/

if( $a->getIndex() == $b->getIndex() ) {
return 0;
}

return ($a->getIndex() < $b->getIndex()) ? -1 : 1;

return $a->getIndex() <=> $b->getIndex();
}
);

Expand Down

0 comments on commit c2ebf58

Please sign in to comment.