<NME> Point.php
<BEF> <?php
declare(strict_types = 1);

namespace SimpleCrud\Fields;

use Atlas\Query\Insert;
use Atlas\Query\Select;
use Atlas\Query\Update;

final class Point extends Field
{
    public static function getFactory(): FieldFactory
    {
        return new FieldFactory(
            self::class,
            ['point']
        );
    }

    public function select(Select $query)
    {
        $name = $this->getName();
        $query->columns("ST_AsText({$this}) as `{$name}`");
    }

    public function format($value): ?array
    {
        if ($value === null) {
            return null;
        }

        //POINT(X Y)
        $points = explode(' ', substr((string) $value, 6, -1), 2);

        return [
            floatval($points[0]),
            floatval($points[1]),
        ];
    }

    public function insert(Insert $query, $value)
    {
        if (self::isValid($value)) {
            $value = sprintf('POINT(%s, %s)', $value[0], $value[1]);
        } else {
            $value = null;
        }

        $query->set($this->info['name'], $value);
    }

    public function update(Update $query, $value)
    {
        if (self::isValid($value)) {
            $value = sprintf('POINT(%s, %s)', $value[0], $value[1]);
        } else {
            $value = null;
        }

        $query->set($this->info['name'], $value);
    }

    /**
     * Check whether the value is valid before save in the database
     * @param mixed $data
     */
    private static function isValid($data): bool
    {
        if (!is_array($data)) {
            return false;
        }

        if (!isset($data[0]) || !isset($data[1]) || count($data) > 2) {
            return false;
        }

        return is_numeric($data[0]) && is_numeric($data[1]);
    }
}

<MSG> fixed return types in Point field

<DFF> @@ -17,7 +17,7 @@ final class Point extends Field
         );
     }
 
-    public function select(Select $query)
+    public function select(Select $query): void
     {
         $name = $this->getName();
         $query->columns("ST_AsText({$this}) as `{$name}`");
@@ -38,7 +38,7 @@ final class Point extends Field
         ];
     }
 
-    public function insert(Insert $query, $value)
+    public function insert(Insert $query, $value): void
     {
         if (self::isValid($value)) {
             $value = sprintf('POINT(%s, %s)', $value[0], $value[1]);
@@ -49,7 +49,7 @@ final class Point extends Field
         $query->set($this->info['name'], $value);
     }
 
-    public function update(Update $query, $value)
+    public function update(Update $query, $value): void
     {
         if (self::isValid($value)) {
             $value = sprintf('POINT(%s, %s)', $value[0], $value[1]);

{'addition_count': 3, 'commit_subject': 'fixed return types in Point field', 'deletion_count': 3, 'file_extension': '.php', 'lang': 'php', 'license': 'mit', 'repo_name': 'oscarotero/simple-crud'}