Skip to content

Commit

Permalink
Drop php7 support
Browse files Browse the repository at this point in the history
  • Loading branch information
flack committed May 31, 2024
1 parent f5dd7ef commit 48b08ef
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions api/midgard/collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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);
}

Expand Down Expand Up @@ -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]);
}
Expand Down
2 changes: 1 addition & 1 deletion api/midgard/object/class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
4 changes: 2 additions & 2 deletions api/midgard/query/builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
23 changes: 9 additions & 14 deletions api/midgard/replicator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions api/midgard/storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
],
"require": {
"php": ">=7.4",
"php": ">=8.0",
"doctrine/orm": "^2.14",
"doctrine/dbal": "^3.5",
"symfony/console": ">=3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/api/dbobject.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/api/mgdobject.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/classgenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down
6 changes: 3 additions & 3 deletions src/query.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand Down
18 changes: 6 additions & 12 deletions src/storage/subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
}
Expand Down

0 comments on commit 48b08ef

Please sign in to comment.