From 48b08ef83a11196264b342f7bb4f8b76e3debb0e Mon Sep 17 00:00:00 2001 From: flack Date: Fri, 31 May 2024 15:36:30 +0200 Subject: [PATCH] Drop php7 support --- .github/workflows/php.yml | 2 +- api/midgard/collector.php | 8 ++++---- api/midgard/object/class.php | 2 +- api/midgard/query/builder.php | 4 ++-- api/midgard/replicator.php | 23 +++++++++-------------- api/midgard/storage.php | 4 ++-- composer.json | 2 +- src/api/dbobject.php | 2 +- src/api/mgdobject.php | 6 +++--- src/classgenerator.php | 2 +- src/driver.php | 10 +++++----- src/query.php | 6 +++--- src/storage/subscriber.php | 18 ++++++------------ 13 files changed, 39 insertions(+), 50 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 1076585..c85f8e7 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -26,7 +26,7 @@ jobs: strategy: matrix: - php: ['7.4', '8.0', '8.1', '8.2', '8.3'] + php: ['8.0', '8.1', '8.2', '8.3'] db: ['mysql', 'sqlite'] fail-fast: false diff --git a/api/midgard/collector.php b/api/midgard/collector.php index a1d23a3..d027fd7 100644 --- a/api/midgard/collector.php +++ b/api/midgard/collector.php @@ -47,7 +47,7 @@ public function add_value_property(string $property) : bool if (!isset($this->value_properties[$property])) { try { $this->value_properties[$property] = $this->build_property_select($property); - } catch (exception $e) { + } catch (exception) { return false; } } @@ -59,8 +59,8 @@ protected function build_property_select(string $property) : string $parsed = $this->parse_constraint_name($property); // for properties like up.name - if ( strpos($property, ".") !== false - && !(strpos($property, "metadata") === 0)) { + if ( str_contains($property, ".") + && !(str_starts_with($property, "metadata"))) { return $parsed['name'] . " as " . str_replace(".", "_", $property); } @@ -102,7 +102,7 @@ public function execute() : bool foreach ($results as $result) { foreach ($result as $key => &$value) { // for metadata fields remove the "metadata_" prefix - if (strpos($key, "metadata_") !== false) { + if (str_contains($key, "metadata_")) { $result[str_replace("metadata_", "", $key)] = $value; unset($result[$key]); } diff --git a/api/midgard/object/class.php b/api/midgard/object/class.php index d1970fe..dd54640 100644 --- a/api/midgard/object/class.php +++ b/api/midgard/object/class.php @@ -24,7 +24,7 @@ private static function resolve_classname(string $guid, bool $include_deleted = try { $result = $qb->getQuery()->getSingleResult(); - } catch (\Doctrine\ORM\NoResultException $e) { + } catch (\Doctrine\ORM\NoResultException) { throw exception::not_exists(); } diff --git a/api/midgard/query/builder.php b/api/midgard/query/builder.php index e4efc54..aef1ce8 100644 --- a/api/midgard/query/builder.php +++ b/api/midgard/query/builder.php @@ -14,7 +14,7 @@ public function add_constraint_with_property(string $name, string $operator, str { try { parent::add_constraint_with_property($name, $operator, $property); - } catch (exception $e) { + } catch (exception) { return false; } return true; @@ -24,7 +24,7 @@ public function add_constraint(string $name, string $operator, $value) : bool { try { parent::add_constraint($name, $operator, $value); - } catch (exception $e) { + } catch (exception) { return false; } return true; diff --git a/api/midgard/replicator.php b/api/midgard/replicator.php index 39e3762..95df57a 100644 --- a/api/midgard/replicator.php +++ b/api/midgard/replicator.php @@ -94,7 +94,7 @@ public static function serialize(dbobject $object) : string if ($name == 'guid') { continue; } - if (strpos($name, 'metadata_') === 0) { + if (str_starts_with($name, 'metadata_')) { $metadata[substr($name, 9)] = $object->$name; } else { $node->addChild($name, self::convert_value($object->$name)); @@ -213,7 +213,7 @@ public static function import_object(dbobject $object, bool $force = false) : bo if ($name == 'id') { continue; } - if (strpos($name, 'metadata_') === false) { + if (!str_contains($name, 'metadata_')) { $dbobject->$name = $object->$name; } } @@ -328,18 +328,13 @@ private static function get_object_action(string $guid) : string ->getScalarResult(); $action = (empty($result)) ? 0 : (int) $result[0]['object_action']; - switch ($action) { - case subscriber::ACTION_CREATE: - return 'created'; - case subscriber::ACTION_UPDATE: - return 'updated'; - case subscriber::ACTION_DELETE: - return 'deleted'; - case subscriber::ACTION_PURGE: - return 'purged'; - default: - return 'none'; - } + return match ($action) { + subscriber::ACTION_CREATE => 'created', + subscriber::ACTION_UPDATE => 'updated', + subscriber::ACTION_DELETE => 'deleted', + subscriber::ACTION_PURGE => 'purged', + default => 'none', + }; } private static function convert_value($value) diff --git a/api/midgard/storage.php b/api/midgard/storage.php index 33df698..410ace1 100644 --- a/api/midgard/storage.php +++ b/api/midgard/storage.php @@ -94,12 +94,12 @@ private static function get_cm(EntityManager $em, string $classname) : ?\Doctrin $factory = $em->getMetadataFactory(); try { return $factory->getMetadataFor($classname); - } catch (MappingException $e) { + } catch (MappingException) { // add namespace $classname = connection::get_fqcn($classname); try { return $factory->getMetadataFor($classname); - } catch (MappingException $e) { + } catch (MappingException) { // check for merged classes (duplicate tablenames) $classname = get_class(new $classname); return $factory->getMetadataFor($classname); diff --git a/composer.json b/composer.json index a630adb..45ec34f 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "php": ">=7.4", + "php": ">=8.0", "doctrine/orm": "^2.14", "doctrine/dbal": "^3.5", "symfony/console": ">=3.0.0", diff --git a/src/api/dbobject.php b/src/api/dbobject.php index bf7019a..1d5a6c2 100644 --- a/src/api/dbobject.php +++ b/src/api/dbobject.php @@ -57,7 +57,7 @@ public function __debugInfo() $this->initialize(); $properties = array_merge($this->cm->getFieldNames(), $this->cm->getAssociationNames(), array_keys($this->cm->midgard['field_aliases'])); $properties = array_filter($properties, function ($input) { - return strpos($input, 'metadata_') === false; + return !str_contains($input, 'metadata_'); }); $ret = []; foreach ($properties as $property) { diff --git a/src/api/mgdobject.php b/src/api/mgdobject.php index 13e3bc0..d4bdc3b 100644 --- a/src/api/mgdobject.php +++ b/src/api/mgdobject.php @@ -57,7 +57,7 @@ public function __debugInfo() if (property_exists($this, 'metadata')) { $metadata = new \stdClass; foreach ($this->cm->getFieldNames() as $name) { - if (strpos($name, 'metadata_') !== false) { + if (str_contains($name, 'metadata_')) { $fieldname = str_replace('metadata_', '', $name); $metadata->$fieldname = $this->__get($name); } @@ -133,7 +133,7 @@ public function get_by_id(int $id) : bool if ($entity instanceof Proxy && !$entity->__isInitialized()) { try { $entity->__load(); - } catch (EntityNotFoundException $e) { + } catch (EntityNotFoundException) { throw exception::object_purged(); } } @@ -688,7 +688,7 @@ public function purge(bool $check_dependencies = true) : bool try { $om = new objectmanager(connection::get_em()); $om->purge($this); - } catch (\Doctrine\ORM\EntityNotFoundException $e) { + } catch (\Doctrine\ORM\EntityNotFoundException) { exception::not_exists(); return false; } catch (\Exception $e) { diff --git a/src/classgenerator.php b/src/classgenerator.php index f4e4262..a643630 100644 --- a/src/classgenerator.php +++ b/src/classgenerator.php @@ -216,7 +216,7 @@ private function write_annotations(type $type) $properties[$alias]->description = 'Alias for ' . $target; } foreach ($properties as $name => $property) { - if (strpos($property->name, 'metadata_') !== 0) { + if (!str_starts_with($property->name, 'metadata_')) { $line = translator::to_phptype($property->type) . ' $' . $name; if ($property->description) { $line .= ' ' . trim($property->description); diff --git a/src/driver.php b/src/driver.php index 5e0bc69..3dd2dcf 100644 --- a/src/driver.php +++ b/src/driver.php @@ -212,30 +212,30 @@ public function loadMetadataForClass($classname, ClassMetadata $metadata) private function parse_dbtype(property $property) : array { - if (strpos($property->dbtype, 'varchar') === 0) { + if (str_starts_with($property->dbtype, 'varchar')) { $mapping = [ 'type' => Types::STRING, ]; - if (substr($property->dbtype, -1) == ')') { + if (str_ends_with($property->dbtype, ')')) { $mapping['length'] = (int) substr($property->dbtype, 8, -1); return $mapping; } - if (substr($property->dbtype, -8) == ') binary') { + if (str_ends_with($property->dbtype, ') binary')) { // see http://www.doctrine-project.org/jira/browse/DDC-1817 $mapping['length'] = (int) substr($property->dbtype, 8, -1); $mapping['comment'] = 'BINARY'; return $mapping; } - } elseif (strpos($property->dbtype, 'set') === 0) { + } elseif (str_starts_with($property->dbtype, 'set')) { // see http://docs.doctrine-project.org/en/latest/cookbook/mysql-enums.html if (!empty($this->dbtypemap[$property->type])) { $mapping = $this->dbtypemap[$property->type]; $mapping['comment'] = $property->dbtype; return $mapping; } - } elseif (strpos(strtolower($property->dbtype), 'decimal') === 0) { + } elseif (str_starts_with(strtolower($property->dbtype), 'decimal')) { $matches = []; preg_match('/DECIMAL\((\d+),(\d+)\)/i', $property->dbtype, $matches); return [ diff --git a/src/query.php b/src/query.php index b27b0fd..3c663f3 100644 --- a/src/query.php +++ b/src/query.php @@ -58,7 +58,7 @@ public function add_constraint(string $name, string $operator, $value) $targetclass = $this->classname; $fieldname = $name; - if (strpos($name, '.') !== false) { + if (str_contains($name, '.')) { $parsed = $this->parse_constraint_name($name); $fieldname = $parsed['column']; $targetclass = $parsed['targetclass']; @@ -91,7 +91,7 @@ public function add_order(string $name, string $direction = 'ASC') : bool } try { $parsed = $this->parse_constraint_name($name); - } catch (exception $e) { + } catch (exception) { return false; } @@ -218,7 +218,7 @@ protected function parse_constraint_name(string $name) : array // metadata $name = str_replace('metadata.', 'metadata_', $name); $column = $name; - if (strpos($name, ".") !== false) { + if (str_contains($name, ".")) { $parts = explode('.', $name); $column = array_pop($parts); foreach ($parts as $part) { diff --git a/src/storage/subscriber.php b/src/storage/subscriber.php index 8f92a06..8d09d56 100644 --- a/src/storage/subscriber.php +++ b/src/storage/subscriber.php @@ -164,17 +164,11 @@ private function calculate_size(ClassMetadata $cm, metadata $entity) : int $size += strlen($entity->$name); } foreach ($cm->getFieldNames() as $name) { - switch ($cm->fieldMappings[$name]['type']) { - case Types::DATETIME_MUTABLE: - $size += 19; // Y-m-d H:i:s - break; - case Types::DATE_MUTABLE: - $size += 10; // Y-m-d - break; - default: - $size += strlen($entity->$name); - break; - } + match ($cm->fieldMappings[$name]['type']) { + Types::DATETIME_MUTABLE => $size += 19, // Y-m-d H:i:s + Types::DATE_MUTABLE => $size += 10, // Y-m-d + default => $size += strlen($entity->$name), + }; } return $size; } @@ -199,7 +193,7 @@ public function onSchemaCreateTable(SchemaCreateTableEventArgs $args) $modified = true; $config['columnDefinition'] = $config['type']->getSQLDeclaration($config, $platform) . ' CHARACTER SET utf8 COLLATE utf8_bin' . $platform->getDefaultValueDeclarationSQL($config); } - if (substr(strtolower(trim($config['comment'])), 0, 3) == 'set') { + if (str_starts_with(strtolower(trim($config['comment'])), 'set')) { $modified = true; $config['columnDefinition'] = $config['comment'] . $platform->getDefaultValueDeclarationSQL($config); }