From 9d874d091bd7eb1908ff7b629da8bacc17696c06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Wed, 14 Oct 2020 10:03:28 +0200 Subject: [PATCH 1/2] Simplify selectColumn --- src/CachePool.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/CachePool.php b/src/CachePool.php index 0cec448..9faecff 100644 --- a/src/CachePool.php +++ b/src/CachePool.php @@ -26,6 +26,8 @@ use function get_option; use function get_transient; use function set_transient; +use function array_key_exists; +use function array_map; /** * {@inheritDoc} @@ -468,15 +470,9 @@ protected function selectColumn(string $query, string $columnName, array $args = $query = $this->prepareQuery($query, $args); $results = $this->wpdb->get_results($query, ARRAY_A); - $column = []; - foreach ($results as $row) { - $value = array_key_exists($columnName, $row) - ? $row[$columnName] - : null; - $column[] = $value; - } - - return $column; + return array_map(function ($row) use ($columnName) { + return $row[$columnName] ?? null; + }, $results); } /** From 0ae92e1602ff11d4db27eee78bd2a669035acaa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Wed, 14 Oct 2020 10:05:24 +0200 Subject: [PATCH 2/2] Update CachePool.php --- src/CachePool.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/CachePool.php b/src/CachePool.php index 9faecff..9ff91bc 100644 --- a/src/CachePool.php +++ b/src/CachePool.php @@ -26,7 +26,6 @@ use function get_option; use function get_transient; use function set_transient; -use function array_key_exists; use function array_map; /**