Completed
Push — master ( 78ebcd...ba06fe )
by Dimas
17:44 queued 04:03
created

schema::get_enumset_values()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 3
eloc 8
nc 3
nop 3
dl 0
loc 14
rs 10
c 1
b 1
f 0
1
<?php
2
3
namespace DB;
4
5
class schema
6
{
7
  /**
8
   * Get ENUM or SET values.
9
   *
10
   * @return array
11
   */
12
  public static function get_enumset_values(\DB\pdo $pdo, string $table, string $field)
13
  {
14
    $type = $pdo->query("SHOW COLUMNS FROM {$table} WHERE Field = '{$field}'")->row_array()['Type'];
15
    if (preg_match("/^enum\(\'(.*)\'\)$/", $type, $matches)) {
16
      $enum = explode("','", $matches[1]);
17
18
      return $enum;
19
    } elseif (preg_match("/^set\(\'(.*)\'\)$/", $type, $matches)) {
20
      $set = explode("','", $matches[1]);
21
22
      return $set;
23
    }
24
25
    return [];
26
  }
27
}
28