Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ Prevents the direct setting of some class variables
];

Overrides the default tablename
default: strtolower(get_class())
default: strtolower(self:class)

### database_config_name (string)

Expand Down
8 changes: 4 additions & 4 deletions lib/Skeleton/Object/Child.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ protected function trait_child_save() {
* @return string $table
*/
public static function trait_get_child_database_table() {
if (property_exists(get_class(), 'class_configuration') and is_array(self::$class_configuration)) {
if (property_exists(self::class, 'class_configuration') and is_array(self::$class_configuration)) {
if (array_key_exists('database_table', self::$class_configuration) and self::$class_configuration['database_table'] === null) {
return null;
} elseif (isset(self::$class_configuration['database_table'])) {
return self::$class_configuration['database_table'];
}
}

return strtolower((new \ReflectionClass(get_class()))->getShortName());
return strtolower((new \ReflectionClass(self::class))->getShortName());
}

/**
Expand All @@ -113,10 +113,10 @@ public static function trait_get_child_database_table() {
* @return string $id
*/
public static function trait_get_parent_table_field_id() {
if (property_exists(get_class(), 'class_configuration') and isset(self::$class_configuration['parent_field_id'])) {
if (property_exists(self::class, 'class_configuration') and isset(self::$class_configuration['parent_field_id'])) {
return self::$class_configuration['parent_field_id'];
} else {
return strtolower((new \ReflectionClass(get_class()))->getParentClass()->getShortName() . '_id');
return strtolower((new \ReflectionClass(self::class))->getParentClass()->getShortName() . '_id');
}
}
}
2 changes: 1 addition & 1 deletion lib/Skeleton/Object/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static function get_by_id($id) {
* If in class_configuration a child_classname field is specified,
* use this
*/
if (property_exists(get_class(), 'class_configuration') && isset(self::$class_configuration['child_classname_field'])) {
if (property_exists(self::class, 'class_configuration') && isset(self::$class_configuration['child_classname_field'])) {
$classname_field = self::$class_configuration['child_classname_field'];
$table = self::trait_get_database_table();
$db = self::trait_get_database();
Expand Down
22 changes: 11 additions & 11 deletions lib/Skeleton/Object/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @var int $id
* @access public
*/
public $id;

Check failure on line 19 in lib/Skeleton/Object/Model.php

View workflow job for this annotation

GitHub Actions / PHP Insights checks

* [Forbidden public property] Do not use public properties. Use method access instead. * [Property type hint] Property \Skeleton\Object\Model::$id does not have native type hint for its value but it should be possible to add it based on @var annotation "int".

Check failure on line 19 in lib/Skeleton/Object/Model.php

View workflow job for this annotation

GitHub Actions / PHP Insights checks

* [Forbidden public property] Do not use public properties. Use method access instead. * [Property type hint] Property \Skeleton\Object\Model::$id does not have native type hint for its value but it should be possible to add it based on @var annotation "int".

/**
* Details
Expand Down Expand Up @@ -68,9 +68,9 @@
* @param int $id
*/
public function __construct($id = null) {
if (property_exists(get_class(), 'class_configuration') && isset(self::$class_configuration['child_classname_field'])) {
if (property_exists(__CLASS__, 'class_configuration') && isset(self::$class_configuration['child_classname_field'])) {
$classname_field = self::$class_configuration['child_classname_field'];
$this->details[$classname_field] = get_class($this);
$this->details[$classname_field] = __CLASS__;
}

if ($id !== null) {
Expand All @@ -94,7 +94,7 @@
throw new \Exception('Classname "' . $classname . '" doesn\'t exist');
}

if (get_class($this) == $classname) {
if (__CLASS__ == $classname) {

Check failure on line 97 in lib/Skeleton/Object/Model.php

View workflow job for this annotation

GitHub Actions / PHP Insights checks

* [Disallow equal operators] Operator == is disallowed, use === instead.

Check failure on line 97 in lib/Skeleton/Object/Model.php

View workflow job for this annotation

GitHub Actions / PHP Insights checks

* [Disallow equal operators] Operator == is disallowed, use === instead.
return $this;
}

Expand Down Expand Up @@ -151,7 +151,7 @@
*/
public function __set($key, $value) {
// Check if the key we want to set exists in the disallow_set variable
if (property_exists(get_class(), 'class_configuration') && isset(self::$class_configuration['disallow_set'])) {
if (property_exists(__CLASS__, 'class_configuration') && isset(self::$class_configuration['disallow_set'])) {
if (is_array(self::$class_configuration['disallow_set'])) {
if (in_array($key, self::$class_configuration['disallow_set'])) {
throw new \Exception('Can not set ' . $key . ' directly');
Expand Down Expand Up @@ -179,7 +179,7 @@
// If a new value is set, let's tag it as dirty
if (isset($this->dirty_fields[$key]) === false && empty($this->id) === false) {
if (array_key_exists($key, $this->details)) {
if (is_numeric($value) === true && $this->details[$key] != $value) {

Check failure on line 182 in lib/Skeleton/Object/Model.php

View workflow job for this annotation

GitHub Actions / PHP Insights checks

* [Disallow equal operators] Operator != is disallowed, use !== instead.

Check failure on line 182 in lib/Skeleton/Object/Model.php

View workflow job for this annotation

GitHub Actions / PHP Insights checks

* [Disallow equal operators] Operator != is disallowed, use !== instead.
$this->dirty_fields[$key] = $this->details[$key];
}

Expand All @@ -189,7 +189,7 @@
}

if (isset($this->child_details) === true && array_key_exists($key, $this->child_details) === true) {
if (is_numeric($value) === true && $this->child_details[$key] != $value) {

Check failure on line 192 in lib/Skeleton/Object/Model.php

View workflow job for this annotation

GitHub Actions / PHP Insights checks

* [Disallow equal operators] Operator != is disallowed, use !== instead.

Check failure on line 192 in lib/Skeleton/Object/Model.php

View workflow job for this annotation

GitHub Actions / PHP Insights checks

* [Disallow equal operators] Operator != is disallowed, use !== instead.
$this->dirty_fields[$key] = $this->child_details[$key];
}

Expand All @@ -216,7 +216,7 @@
if (!class_exists('\Skeleton\I18n\Object\Text')) {
throw new \Exception('Skeleton package "skeleton-i18n" needs to be installed to use object text');
}
list($language, $label) = explode('_', str_replace('text_', '', $key), 2);

Check failure on line 219 in lib/Skeleton/Object/Model.php

View workflow job for this annotation

GitHub Actions / PHP Insights checks

* [Unused variable] Unused variable $language. * [Short list] list(...) is forbidden, use [...] instead.

Check failure on line 219 in lib/Skeleton/Object/Model.php

View workflow job for this annotation

GitHub Actions / PHP Insights checks

* [Unused variable] Unused variable $language. * [Short list] list(...) is forbidden, use [...] instead.

if (!in_array($label, self::$object_text_fields)) {
throw new \Exception('Incorrect text field:' . $label);
Expand All @@ -226,7 +226,7 @@
$this->trait_get_object_text($key);
}

if ($this->object_text_cache[$key] != $value) {

Check failure on line 229 in lib/Skeleton/Object/Model.php

View workflow job for this annotation

GitHub Actions / PHP Insights checks

* [Disallow equal operators] Operator != is disallowed, use !== instead.

Check failure on line 229 in lib/Skeleton/Object/Model.php

View workflow job for this annotation

GitHub Actions / PHP Insights checks

* [Disallow equal operators] Operator != is disallowed, use !== instead.
$this->object_text_updated[$key] = $this->$key;
$this->object_text_cache[$key] = $value;
}
Expand Down Expand Up @@ -321,7 +321,7 @@

if (isset(self::$object_text_fields)) {
if (strpos($key, 'text_') === 0) {
list($language, $label) = explode('_', str_replace('text_', '', $key), 2);

Check failure on line 324 in lib/Skeleton/Object/Model.php

View workflow job for this annotation

GitHub Actions / PHP Insights checks

* [Unused variable] Unused variable $language. * [Function call argument spacing] Expected 1 space after comma in argument list; 2 found * [Short list] list(...) is forbidden, use [...] instead.

Check failure on line 324 in lib/Skeleton/Object/Model.php

View workflow job for this annotation

GitHub Actions / PHP Insights checks

* [Unused variable] Unused variable $language. * [Function call argument spacing] Expected 1 space after comma in argument list; 2 found * [Short list] list(...) is forbidden, use [...] instead.

if (!in_array($label, self::$object_text_fields)) {
return false;
Expand Down Expand Up @@ -441,7 +441,7 @@
* @return Database $database
*/
protected static function trait_get_database() {
if (property_exists(get_class(), 'class_configuration') && isset(self::$class_configuration['database_config_name'])) {
if (property_exists(self::class, 'class_configuration') && isset(self::$class_configuration['database_config_name'])) {
$db = Database::get(self::$class_configuration['database_config_name']);
} else {
$db = Database::get();
Expand All @@ -456,10 +456,10 @@
* @return string $table
*/
public static function trait_get_database_table() {
if (property_exists(get_class(), 'class_configuration') && isset(self::$class_configuration['database_table'])) {
if (property_exists(self::class, 'class_configuration') && isset(self::$class_configuration['database_table'])) {
return self::$class_configuration['database_table'];
} else {
return strtolower((new \ReflectionClass(get_class()))->getShortName());
return strtolower((new \ReflectionClass(self::class))->getShortName());
}
}

Expand All @@ -470,7 +470,7 @@
* @return string $id
*/
protected static function trait_get_table_field_id() {
if (property_exists(get_class(), 'class_configuration') && isset(self::$class_configuration['table_field_id'])) {
if (property_exists(self::class, 'class_configuration') && isset(self::$class_configuration['table_field_id'])) {
return self::$class_configuration['table_field_id'];
} else {
return 'id';
Expand All @@ -484,7 +484,7 @@
* @return string $created
*/
private static function trait_get_table_field_created() {
if (property_exists(get_class(), 'class_configuration') && isset(self::$class_configuration['table_field_created'])) {
if (property_exists(self::class, 'class_configuration') && isset(self::$class_configuration['table_field_created'])) {
return self::$class_configuration['table_field_created'];
} else {
return 'created';
Expand All @@ -498,7 +498,7 @@
* @return string $updated
*/
private static function trait_get_table_field_updated() {
if (property_exists(get_class(), 'class_configuration') && isset(self::$class_configuration['table_field_updated'])) {
if (property_exists(self::class, 'class_configuration') && isset(self::$class_configuration['table_field_updated'])) {
return self::$class_configuration['table_field_updated'];
} else {
return 'updated';
Expand All @@ -512,7 +512,7 @@
* @return string $archived
*/
private static function trait_get_table_field_archived() {
if (property_exists(get_class(), 'class_configuration') && isset(self::$class_configuration['table_field_archived'])) {
if (property_exists(self::class, 'class_configuration') && isset(self::$class_configuration['table_field_archived'])) {
return self::$class_configuration['table_field_archived'];
} else {
return 'archived';
Expand Down
6 changes: 3 additions & 3 deletions lib/Skeleton/Object/Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function generate_number() {
/**
* We need to know the fields that divide the numbers groups of unique numbers
*/
if (property_exists(get_class(), 'class_configuration') AND isset(self::$class_configuration['number_dividers'])) {
if (property_exists(__CLASS__, 'class_configuration') AND isset(self::$class_configuration['number_dividers'])) {
$number_dividers = self::$class_configuration['number_dividers'];
}

Expand All @@ -36,7 +36,7 @@ protected function generate_number() {
/**
* Which field do we need to store the number
*/
if (property_exists(get_class(), 'class_configuration') AND isset(self::$class_configuration['number_field'])) {
if (property_exists(__CLASS__, 'class_configuration') AND isset(self::$class_configuration['number_field'])) {
$number_field = self::$class_configuration['number_field'];
}

Expand All @@ -63,7 +63,7 @@ protected function generate_number() {
$conditions = [];
foreach ($number_dividers as $number_divider) {
if (empty($this->$number_divider)) {
throw new \Exception('Cannot create number for ' . get_class() . '. Number divider ' . $number_divider . ' is empty');
throw new \Exception('Cannot create number for ' . __CLASS__ . '. Number divider ' . $number_divider . ' is empty');
}
$conditions[$number_divider] = $this->$number_divider;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Skeleton/Object/Slug.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ trait Slug {
private function trait_slug_get_base(): string {
$sluggable_field = 'name';

if (property_exists(get_class(), 'class_configuration') AND isset(self::$class_configuration['sluggable'])) {
if (property_exists(__CLASS__, 'class_configuration') AND isset(self::$class_configuration['sluggable'])) {
$sluggable_field = self::$class_configuration['sluggable'];
}

Expand Down
Loading