Commit: b78a07146df1fdf804df21688a98d98273f12b6b Author: Peter Kokot <peterko...@gmail.com> Wed, 26 Dec 2018 22:27:50 +0100 Parents: 402a43856329884eae5b58e83b656b08a6c2ab01 Branches: master
Link: http://git.php.net/?p=web/bugs.git;a=commitdiff;h=b78a07146df1fdf804df21688a98d98273f12b6b Log: Refactor repository classes to use vanilla PDOStatement Current goal is to use as close to PDO expected functionality without overriding and making custom methods due to easier understanding of the app itself for people working on the code and contributors. This patch refactors repository classes to use the expected \PDOStatement without method chaining. Changed paths: M src/Repository/ObsoletePatchRepository.php M src/Repository/PackageRepository.php M src/Repository/PatchRepository.php M src/Repository/PullRequestRepository.php Diff: diff --git a/src/Repository/ObsoletePatchRepository.php b/src/Repository/ObsoletePatchRepository.php index 2682cee..f8ff1ae 100644 --- a/src/Repository/ObsoletePatchRepository.php +++ b/src/Repository/ObsoletePatchRepository.php @@ -31,7 +31,10 @@ class ObsoletePatchRepository WHERE bugdb_id = ? AND obsolete_patch = ? AND obsolete_revision = ? '; - return $this->dbh->prepare($sql)->execute([$bugId, $patch, $revision])->fetchAll(); + $statement = $this->dbh->prepare($sql); + $statement->execute([$bugId, $patch, $revision]); + + return $statement->fetchAll(); } /** @@ -44,6 +47,9 @@ class ObsoletePatchRepository WHERE bugdb_id = ? AND patch = ? AND revision = ? '; - return $this->dbh->prepare($sql)->execute([$bugId, $patch, $revision])->fetchAll(); + $statement = $this->dbh->prepare($sql); + $statement->execute([$bugId, $patch, $revision]); + + return $statement->fetchAll(); } } diff --git a/src/Repository/PackageRepository.php b/src/Repository/PackageRepository.php index aaaa399..ae64a1a 100644 --- a/src/Repository/PackageRepository.php +++ b/src/Repository/PackageRepository.php @@ -46,7 +46,9 @@ class PackageRepository $sql .= ' ORDER BY parent, disabled, id'; - $data = $this->dbh->prepare($sql)->execute($arguments)->fetchAll(); + $statement = $this->dbh->prepare($sql); + $statement->execute($arguments); + $data = $statement->fetchAll(); return $this->getNested($data); } @@ -67,7 +69,10 @@ class PackageRepository $sql .= ' ORDER BY parent, id'; - $data = $this->dbh->prepare($sql)->execute($arguments)->fetchAll(); + $statement = $this->dbh->prepare($sql); + $statement->execute($arguments); + + $data = $statement->fetchAll(); return $this->getNested($data); } diff --git a/src/Repository/PatchRepository.php b/src/Repository/PatchRepository.php index 971c1ff..9fd9031 100644 --- a/src/Repository/PatchRepository.php +++ b/src/Repository/PatchRepository.php @@ -39,7 +39,10 @@ class PatchRepository ORDER BY revision DESC '; - return $this->dbh->prepare($sql)->execute([$bugId])->fetchAll(); + $statement = $this->dbh->prepare($sql); + $statement->execute([$bugId]); + + return $statement->fetchAll(); } /** @@ -54,7 +57,10 @@ class PatchRepository $arguments = [$bugId, $patch, $revision]; - return $this->dbh->prepare($sql)->execute($arguments)->fetch(\PDO::FETCH_NUM)[0]; + $statement = $this->dbh->prepare($sql); + $statement->execute($arguments); + + return $statement->fetch(\PDO::FETCH_NUM)[0]; } /** @@ -68,7 +74,10 @@ class PatchRepository ORDER BY revision DESC '; - return $this->dbh->prepare($sql)->execute([$bugId, $patch])->fetchAll(); + $statement = $this->dbh->prepare($sql); + $statement->execute([$bugId, $patch]); + + return $statement->fetchAll(); } /** @@ -81,7 +90,10 @@ class PatchRepository WHERE bugdb_id = ? AND patch = ? AND revision = ? '; - if ($this->dbh->prepare($sql)->execute([$bugId, $name, $revision])->fetch(\PDO::FETCH_NUM)[0]) { + $statement = $this->dbh->prepare($sql); + $statement->execute([$bugId, $name, $revision]); + + if ($statement->fetch(\PDO::FETCH_NUM)[0]) { $contents = @file_get_contents($this->getPatchPath($bugId, $name, $revision)); if (!$contents) { diff --git a/src/Repository/PullRequestRepository.php b/src/Repository/PullRequestRepository.php index 89a72ce..0d6bd7e 100644 --- a/src/Repository/PullRequestRepository.php +++ b/src/Repository/PullRequestRepository.php @@ -35,6 +35,9 @@ class PullRequestRepository ORDER BY github_repo, github_pull_id DESC '; - return $this->dbh->prepare($sql)->execute([$bugId])->fetchAll(); + $statement = $this->dbh->prepare($sql); + $statement->execute([$bugId]); + + return $statement->fetchAll(); } } -- PHP Webmaster List Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php