From 97a2816ab7d8b28e4bcadcde647c245bf6de69f8 Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Wed, 17 May 2017 12:57:11 -0400 Subject: [PATCH] PHPCS fixes. --- src/Robo/Blt.php | 2 +- src/Robo/Datastore/DataStoreInterface.php | 33 +++++---- src/Robo/Datastore/FileStore.php | 84 ++++++++++++----------- 3 files changed, 67 insertions(+), 52 deletions(-) diff --git a/src/Robo/Blt.php b/src/Robo/Blt.php index 9b9140e637..20dc4fe117 100644 --- a/src/Robo/Blt.php +++ b/src/Robo/Blt.php @@ -198,7 +198,7 @@ public function configureContainer($container) { $container->share('filesetManager', FilesetManager::class); - // Install our command cache into the command factory + // Install our command cache into the command factory. $commandCacheDir = $this->getConfig()->get('blt.command-cache-dir'); $commandCacheDataStore = new FileStore($commandCacheDir); /** @var \Consolidation\AnnotatedCommand\AnnotatedCommandFactory $factory */ diff --git a/src/Robo/Datastore/DataStoreInterface.php b/src/Robo/Datastore/DataStoreInterface.php index 018ba198fc..978c453a25 100644 --- a/src/Robo/Datastore/DataStoreInterface.php +++ b/src/Robo/Datastore/DataStoreInterface.php @@ -3,44 +3,53 @@ namespace Acquia\Blt\Robo\Datastore; /** - * Interface DataStoreInterface + * Interface DataStoreInterface. */ -interface DataStoreInterface -{ +interface DataStoreInterface { + /** - * Reads retrieves data from the store + * Reads retrieves data from the store. + * + * @param string $key + * A key. * - * @param string $key A key * @return mixed The value fpr the given key or null. */ public function get($key); /** - * Saves a value with the given key + * Saves a value with the given key. * - * @param string $key A key - * @param mixed $data Data to save to the store + * @param string $key + * A key. + * @param mixed $data + * Data to save to the store. */ public function set($key, $data); /** - * Checks if a key is in the store + * Checks if a key is in the store. + * + * @param string $key + * A key. * - * @param string $key A key * @return bool Whether a value exists with the given key */ public function has($key); /** - * Remove value from the store + * Remove value from the store. * - * @param string $key A key + * @param string $key + * A key. */ public function remove($key); /** * Return a list of all keys in the store. + * * @return array A list of keys */ public function keys(); + } diff --git a/src/Robo/Datastore/FileStore.php b/src/Robo/Datastore/FileStore.php index b907a84e18..cded4d0564 100644 --- a/src/Robo/Datastore/FileStore.php +++ b/src/Robo/Datastore/FileStore.php @@ -5,78 +5,81 @@ /** * Class FileStore. */ -class FileStore implements DataStoreInterface -{ +class FileStore implements DataStoreInterface { /** - * @var string The directory to store the data files in. + * @var stringThedirectorytostorethedatafilesin */ protected $directory; - public function __construct($directory) - { + /** + * + */ + public function __construct($directory) { $this->directory = $directory; } /** - * Reads retrieves data from the store + * Reads retrieves data from the store. + * + * @param string $key + * A key. * - * @param string $key A key * @return mixed The value fpr the given key or null. */ - public function get($key) - { - $out = null; + public function get($key) { + $out = NULL; // Read the json encoded value from disk if it exists. $path = $this->getFileName($key); if (file_exists($path)) { $out = file_get_contents($path); - $out = json_decode($out, true); + $out = json_decode($out, TRUE); } return $out; } /** - * Saves a value with the given key + * Saves a value with the given key. * - * @param string $key A key - * @param mixed $data Data to save to the store + * @param string $key + * A key. + * @param mixed $data + * Data to save to the store. */ - public function set($key, $data) - { - $path = $this->getFileName($key, true); + public function set($key, $data) { + $path = $this->getFileName($key, TRUE); file_put_contents($path, json_encode($data)); } /** - * Checks if a key is in the store + * Checks if a key is in the store. + * + * @param string $key + * A key. * - * @param string $key A key * @return bool Whether a value exists with the given key. */ - public function has($key) - { + public function has($key) { $path = $this->getFileName($key); return file_exists($path); } /** - * Remove value from the store + * Remove value from the store. * - * @param string $key A key + * @param string $key + * A key. */ - public function remove($key) - { - $path = $this->getFileName($key, true); + public function remove($key) { + $path = $this->getFileName($key, TRUE); if (file_exists($path)) { unlink($path); } } /** - * Remove all values from the store + * Remove all values from the store. */ - public function removeAll() - { + public function removeAll() { foreach ($this->keys() as $key) { $this->remove($key); } @@ -84,10 +87,10 @@ public function removeAll() /** * Return a list of all keys in the store. + * * @return array A list of keys */ - public function keys() - { + public function keys() { $root = $this->directory; if (file_exists($root) && is_readable($root)) { return array_diff(scandir($root), array('..', '.')); @@ -97,12 +100,15 @@ public function keys() /** * Get a valid file name for the given key. - * @param string $key The data key to be written or read + * + * @param string $key + * The data key to be written or read. + * * @return string A file path + * * @throws \Exception */ - protected function getFileName($key, $writable = false) - { + protected function getFileName($key, $writable = FALSE) { $key = $this->cleanKey($key); if ($writable) { @@ -121,24 +127,23 @@ protected function getFileName($key, $writable = false) * few already safe keys. * * @param $key + * * @return mixed */ - protected function cleanKey($key) - { + protected function cleanKey($key) { return preg_replace('/[^a-zA-Z0-9\-\_\@\.]/', '-', $key); } /** * Check that the directory is writable and create it if we can. */ - protected function ensureDirectoryWritable() - { + protected function ensureDirectoryWritable() { // Reality check to prevent stomping on the local filesystem if there is something wrong with the config. if (!$this->directory) { throw new \Exception('Could not save data to a file because the path setting is mis-configured.'); } - $writable = is_dir($this->directory) || (!file_exists($this->directory) && @mkdir($this->directory, 0777, true)); + $writable = is_dir($this->directory) || (!file_exists($this->directory) && @mkdir($this->directory, 0777, TRUE)); $writable = $writable && is_writable($this->directory); if (!$writable) { throw new \Exception( @@ -147,4 +152,5 @@ protected function ensureDirectoryWritable() ); } } + }