diff src/Replacer/Replacer.php @ 7:769a17898cc0

Various changes to the generators and replacers - probably mostly just formatting
author luka
date Wed, 18 Oct 2023 21:04:11 -0400
parents b0b2e79ad8e6
children d4730c14806d
line wrap: on
line diff
--- a/src/Replacer/Replacer.php	Thu Oct 12 19:44:22 2023 -0400
+++ b/src/Replacer/Replacer.php	Wed Oct 18 21:04:11 2023 -0400
@@ -12,8 +12,7 @@
      *
      * @var string
      */
-    protected $controller_prefix = "";
-
+    protected $controller_prefix = '';
 
     /**
      * Prefix and Suffix for controller.
@@ -21,28 +20,27 @@
      *
      * @var string
      */
-    protected $controller_suffix = "Controller";
-
+    protected $controller_suffix = 'Controller';
 
     /**
      * Finds all places in a string that could be replaced.
      * Returns an array of all potential replacements as they
      * appear in the target.
      */
-    public function get_all_inserts(string $target): array
+    public function get_all_keywords(string $target): array
     {
-        //find all the matches to our expected syntax
+        // find all the matches to our expected syntax
         $matches = [];
         preg_match_all('/{{[\sa-zA-Z\-_]+}}/', $target, $matches);
         // sort the array and return unique values
         sort($matches[0]);
+
         return array_values(array_unique($matches[0]));
     }
 
-
     public function apply_replacements(string $target): string
     {
-        $inserts = $this->get_all_inserts($target);
+        $inserts = $this->get_all_keywords($target);
         $available_replacements = $this->get_available_replacements();
 
         $target = str_replace(
@@ -58,28 +56,28 @@
     {
         $table_name = $this->getTableInput();
         $replacements = [
-                    "{{ class }}" => $this->getClassName($table_name),
-                    "{{ controllerName }}" => $this->controller_name($table_name),
-                    "{{ model }}" => $this->model_name($table_name),
-                    "{{ modelVariable }}" => $this->model_variable($table_name),
-                    "{{ namespace }}" => $this->{'get' . $this->type . 'Namespace'}($table_name),
-                    "{{ namespacedModel }}" => $this->getNamespacedModel($table_name),
-                    "{{ requestUses }}" => $this->getRequestUses($table_name),
-                    "{{ rootNamespace }}" => $this->getRootNamespace(),
-                    "{{ storeRequest }}" => $this->store_request_name($table_name),
-                    "{{ tableName }}" => $table_name,
-                    "{{ updateRequest }}" => $this->update_request_name($table_name),
+                    '{{ class }}' => $this->getClassName($table_name),
+                    '{{ controllerName }}' => $this->controller_name($table_name),
+                    '{{ model }}' => $this->model_name($table_name),
+                    '{{ modelVariable }}' => $this->model_variable($table_name),
+                    '{{ namespace }}' => $this->{'get'.$this->type.'Namespace'}($table_name),
+                    '{{ namespacedModel }}' => $this->getNamespacedModel($table_name),
+                    '{{ requestUses }}' => $this->getRequestUses($table_name),
+                    '{{ rootNamespace }}' => $this->getRootNamespace(),
+                    '{{ storeRequest }}' => $this->store_request_name($table_name),
+                    '{{ tableName }}' => $table_name,
+                    '{{ updateRequest }}' => $this->update_request_name($table_name),
         ];
 
         return $replacements;
     }
 
-    ////////////////////////////////////////////
+    // //////////////////////////////////////////
     //				Internals and Classes   				//
-    ////////////////////////////////////////////
+    // //////////////////////////////////////////
 
     /**
-     * Model names are generated in uppercase first Camel case
+     * Model names are generated in uppercase first Camel case.
      */
     public function model_name(string $name): string
     {
@@ -87,7 +85,7 @@
     }
 
     /**
-     * Model variable is standardly just a singular version of the table name
+     * Model variable is standardly just a singular version of the table name.
      */
     public function model_variable(string $name): string
     {
@@ -96,29 +94,28 @@
 
     /**
      * Controller names are generated in uppercase first Camel case
-     * and wrapped in the prefix and suffix
+     * and wrapped in the prefix and suffix.
      */
     public function controller_name(string $name): string
     {
-        return $this->controller_prefix .
-            $this->model_name($name) .
+        return $this->controller_prefix.
+            $this->model_name($name).
             $this->controller_suffix;
     }
 
     public function store_request_name(string $name): string
     {
-        return 'Store' . $this->model_name($name) . 'Request';
+        return 'Store'.$this->model_name($name).'Request';
     }
 
     public function update_request_name(string $name): string
     {
-        return 'Update' . $this->model_name($name) . 'Request';
+        return 'Update'.$this->model_name($name).'Request';
     }
 
-
-    ////////////////////////////////////////////
+    // //////////////////////////////////////////
     //							Namespaces			   				//
-    ////////////////////////////////////////////
+    // //////////////////////////////////////////
 
     public function getRootNamespace()
     {
@@ -127,22 +124,22 @@
 
     public function getModelNamespace(string $name = '')
     {
-        return $this->getRootNamespace() . 'Models';
+        return $this->getRootNamespace().'Models';
     }
 
     public function getNamespacedModel(string $name = '')
     {
-        return $this->getModelNamespace() . '\\' . $this->model_name($name);
+        return $this->getModelNamespace().'\\'.$this->model_name($name);
     }
 
     public function getControllerNamespace(string $name = '')
     {
-        return $this->getRootNamespace() . 'Http\\Controllers';
+        return $this->getRootNamespace().'Http\\Controllers';
     }
 
     public function getRequestNamespace(string $name)
     {
-        return $this->getRootNamespace() . 'Http\\Requests\\' . $this->model_name($name);
+        return $this->getRootNamespace().'Http\\Requests\\'.$this->model_name($name);
     }
 
     public function getStoreRequestNamespace(string $name)
@@ -158,24 +155,22 @@
     public function getRequestUses(string $name)
     {
         return implode("\n", [
-            "use " . $this->getRequestNamespace($name) . '\\' . $this->store_request_name($name) . ';',
-            "use " . $this->getRequestNamespace($name) . '\\' . $this->update_request_name($name) . ';',
+            'use '.$this->getRequestNamespace($name).'\\'.$this->store_request_name($name).';',
+            'use '.$this->getRequestNamespace($name).'\\'.$this->update_request_name($name).';',
         ]);
     }
 
-
     public function getRouteNamespace(string $name = '')
     {
-        return $this->getRootNamespace() . 'Http\\Controllers';
+        return $this->getRootNamespace().'Http\\Controllers';
     }
 
-
-    ////////////////////////////////////////////
+    // //////////////////////////////////////////
     //				Language and Presentables				//
-    ////////////////////////////////////////////
+    // //////////////////////////////////////////
 
     /**
-     * Breaks up a string and makes it human readable
+     * Breaks up a string and makes it human readable.
      *
      * This function assumes that the inputted name is camel case
      */
@@ -185,7 +180,7 @@
     }
 
     /**
-     * Breaks up a string and makes it human readable and lowecase
+     * Breaks up a string and makes it human readable and lowecase.
      *
      * This function assumes that the inputted name is camel case
      */