diff src/Replacer/Replacer.php @ 23:827efbf4d73c main-dev

Huge changes to the relationships for models and more complex
author Luka Sitas <sitas.luka.97@gmail.com>
date Fri, 11 Apr 2025 20:50:20 -0400
parents f0b0d014e448
children 1a717c7b211f
line wrap: on
line diff
--- a/src/Replacer/Replacer.php	Wed Feb 26 20:12:17 2025 -0500
+++ b/src/Replacer/Replacer.php	Fri Apr 11 20:50:20 2025 -0400
@@ -9,25 +9,18 @@
     /**
      * Prefix and Suffix for controller.
      * Usage is up to the user.
-     *
-     * @var string
      */
     protected string $controller_prefix = '';
 
     /**
      * Prefix and Suffix for controller.
      * Usage is up to the user.
-     *
-     * @var string
      */
     protected string $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.
-     *
-     * @param string $target
-     * @return array
      */
     public function get_all_keywords(string $target): array
     {
@@ -42,9 +35,6 @@
 
     /**
      * Apply replacements to the target string.
-     *
-     * @param string $target
-     * @return string
      */
     public function apply_replacements(string $target): string
     {
@@ -60,8 +50,6 @@
 
     /**
      * Get available replacements for string replacements.
-     *
-     * @return array
      */
     public function get_available_replacements(): array
     {
@@ -72,7 +60,7 @@
             '{{ 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),
+            '{{ namespace }}' => $this->{'get'.$this->type.'Namespace'}($table_name),
             '{{ namespacedModel }}' => $this->getNamespacedModel($table_name),
             '{{ requestUses }}' => $this->getRequestUses($table_name),
             '{{ rootNamespace }}' => $this->getRootNamespace(),
@@ -86,9 +74,6 @@
 
     /**
      * Generate model name in Studly case.
-     *
-     * @param string $name
-     * @return string
      */
     public function model_name(string $name): string
     {
@@ -97,9 +82,6 @@
 
     /**
      * Generate singular model variable name.
-     *
-     * @param string $name
-     * @return string
      */
     public function model_variable(string $name): string
     {
@@ -108,37 +90,28 @@
 
     /**
      * Generate controller name using prefix/suffix and studly case.
-     *
-     * @param string $name
-     * @return string
      */
     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;
     }
 
     /**
      * Generate the store request name.
-     *
-     * @param string $name
-     * @return string
      */
     public function store_request_name(string $name): string
     {
-        return 'Store' . $this->model_name($name) . 'Request';
+        return 'Store'.$this->model_name($name).'Request';
     }
 
     /**
      * Generate the update request name.
-     *
-     * @param string $name
-     * @return string
      */
     public function update_request_name(string $name): string
     {
-        return 'Update' . $this->model_name($name) . 'Request';
+        return 'Update'.$this->model_name($name).'Request';
     }
 
     // Namespace Methods
@@ -146,8 +119,6 @@
 
     /**
      * Get the root namespace for the application.
-     *
-     * @return string
      */
     public function getRootNamespace(): string
     {
@@ -156,53 +127,38 @@
 
     /**
      * Get the model namespace.
-     *
-     * @param string $name
-     * @return string
      */
     public function getModelNamespace(string $name = ''): string
     {
-        return $this->getRootNamespace() . 'Models';
+        return $this->getRootNamespace().'Models';
     }
 
     /**
      * Get the fully-qualified namespaced model class.
-     *
-     * @param string $name
-     * @return string
      */
     public function getNamespacedModel(string $name = ''): string
     {
-        return $this->getModelNamespace() . '\\' . $this->model_name($name);
+        return $this->getModelNamespace().'\\'.$this->model_name($name);
     }
 
     /**
      * Get the controller namespace.
-     *
-     * @param string $name
-     * @return string
      */
     public function getControllerNamespace(string $name = ''): string
     {
-        return $this->getRootNamespace() . 'Http\\Controllers';
+        return $this->getRootNamespace().'Http\\Controllers';
     }
 
     /**
      * Get the request namespace.
-     *
-     * @param string $name
-     * @return string
      */
     public function getRequestNamespace(string $name): string
     {
-        return $this->getRootNamespace() . 'Http\\Requests\\' . $this->model_name($name);
+        return $this->getRootNamespace().'Http\\Requests\\'.$this->model_name($name);
     }
 
     /**
      * Get the store request namespace.
-     *
-     * @param string $name
-     * @return string
      */
     public function getStoreRequestNamespace(string $name): string
     {
@@ -211,9 +167,6 @@
 
     /**
      * Get the update request namespace.
-     *
-     * @param string $name
-     * @return string
      */
     public function getUpdateRequestNamespace(string $name): string
     {
@@ -222,15 +175,12 @@
 
     /**
      * Get the request uses string for replacement.
-     *
-     * @param string $name
-     * @return string
      */
     public function getRequestUses(string $name): string
     {
         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).';',
         ]);
     }
 
@@ -239,9 +189,6 @@
     /**
      * Convert a string to a human-readable format.
      * Assumes camel case input.
-     *
-     * @param string $name
-     * @return string
      */
     public function human_readable(string $name): string
     {
@@ -251,9 +198,6 @@
     /**
      * Convert a string to a lowercase human-readable format.
      * Assumes camel case input.
-     *
-     * @param string $name
-     * @return string
      */
     public function human_readable_lc(string $name): string
     {