Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions src/MartinGeorgiev/Doctrine/DBAL/Type.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace MartinGeorgiev\Doctrine\DBAL;

abstract class Type
{
public const BIGINT_ARRAY = 'bigint[]';
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

🧩 Analysis chain

Verify completeness and consistency with other type classes.

This implementation introduces a central Type class with only the BIGINT_ARRAY constant. Based on the repository's learnings, there are many other array types (text[], jsonb[], inet[], point[], etc.) that should also have constants defined here if the goal is to centralize type name constants.

Additionally, the class name Type in namespace MartinGeorgiev\Doctrine\DBAL might cause confusion with Doctrine's own Doctrine\DBAL\Types\Type class.

Run the following script to check all existing type classes and identify which ones should have constants added:

This will help verify:

  1. How many type classes exist that should potentially use centralized constants
  2. Whether the current approach is consistent across all types
  3. The inheritance hierarchy to understand the design pattern

🏁 Script executed:

#!/bin/bash
# Description: Find all type classes and their TYPE_NAME declarations to assess completeness

# Find all type classes in the Types directory
echo "=== All Type Classes ==="
fd -e php -p 'src/MartinGeorgiev/Doctrine/DBAL/Types/.*\.php$' --exec basename {}

echo -e "\n=== TYPE_NAME Declarations ==="
# Search for TYPE_NAME constant declarations across all type classes
rg -n -A1 'protected const TYPE_NAME' src/MartinGeorgiev/Doctrine/DBAL/Types/

echo -e "\n=== Checking for BaseType or similar parent classes ==="
# Find base classes to understand the inheritance hierarchy
rg -n 'class.*extends (Base\w+|AbstractType)' src/MartinGeorgiev/Doctrine/DBAL/Types/

Length of output: 10459


Complete the centralization of type constants or document this as a staged migration.

Verification confirms the incomplete pattern: only BigIntArray uses the new Type::BIGINT_ARRAY constant, while 27 other types still define their TYPE_NAME as string literals ('text[]', 'jsonb[]', 'inet[]', 'point[]', 'macaddr[]', 'cidr[]', 'bool[]', 'real[]', 'integer[]', 'smallint[]', 'double precision[]', 'geometry[]', 'geography[]', 'point', 'inet', 'cidr', 'macaddr', 'ltree', 'jsonb', 'geometry', 'geography', 'tstzrange', 'tsrange', 'int4range', 'int8range', 'numrange', 'daterange').

Either:

  1. Migrate all type classes to use constants defined in the Type class (TextArray, PointArray, JsonbArray, etc.)
  2. Document this as a staged refactor and track remaining types for future PRs
  3. Revert and maintain string literals for consistency

Mixing both approaches (one type using constants, others using strings) creates inconsistent patterns and technical debt.

🤖 Prompt for AI Agents
In src/MartinGeorgiev/Doctrine/DBAL/Type.php around lines 7-10, the code
introduced a single constant (BIGINT_ARRAY) while the other 27 types still use
string literals, causing inconsistent patterns; fix by adding constants for all
remaining type names (e.g., TEXT_ARRAY, JSONB_ARRAY, INET, POINT_ARRAY, MACADDR,
CIDR, BOOL_ARRAY, REAL_ARRAY, INTEGER_ARRAY, SMALLINT_ARRAY,
DOUBLE_PRECISION_ARRAY, GEOMETRY, GEOGRAPHY, TSTZRANGE, TSRANGE, INT4RANGE,
INT8RANGE, NUMRANGE, DATERANGE, LTREE, JSONB, POINT, etc.) into this Type class
and update each type class to reference Type::CONSTANT for its TYPE_NAME; if you
cannot migrate all in one PR, instead add a clear TODO and documentation comment
in this file describing staged migration and list the remaining types plus
create/reference a tracking issue so the mixed approach is explicitly tracked.

4 changes: 3 additions & 1 deletion src/MartinGeorgiev/Doctrine/DBAL/Types/BigIntArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace MartinGeorgiev\Doctrine\DBAL\Types;

use MartinGeorgiev\Doctrine\DBAL\Type;

/**
* Implementation of PostgreSQL BIGINT[] data type.
*
Expand All @@ -17,7 +19,7 @@ class BigIntArray extends BaseIntegerArray
/**
* @var string
*/
protected const TYPE_NAME = 'bigint[]';
protected const TYPE_NAME = Type::BIGINT_ARRAY;

protected function getMinValue(): int
{
Expand Down
Loading