| Conditions | 15 |
| Paths | 440 |
| Total Lines | 137 |
| Code Lines | 97 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 10 | ||
| Bugs | 5 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 41 | protected function doExecute() |
||
| 42 | { |
||
| 43 | |||
| 44 | $location = $this->input->getOption("location"); |
||
| 45 | if ($location){ |
||
| 46 | $config = $this->app["config"]; |
||
| 47 | $projects = $config["projects"]; |
||
| 48 | $projects["path"] = $location; |
||
| 49 | $config["projects"] = $projects; |
||
| 50 | $this->app["config"]= $config; |
||
| 51 | } |
||
| 52 | |||
| 53 | $projectname = $this->dialogProvider->askFor("Please enter the name of the project", 'project'); |
||
| 54 | $hostname = $this->dialogProvider->askFor("Please enter the hostname of the server", 'host'); |
||
| 55 | |||
| 56 | $this->dialogProvider->logStep("Checking preconditions"); |
||
| 57 | $this->dialogProvider->logTask("Checking the server"); |
||
| 58 | $exists = $this->isRemoteProjectAvailable($projectname, $hostname); |
||
| 59 | if (!$exists) { |
||
| 60 | $this->dialogProvider->logError("The project " . $projectname . " does not exist on " . $hostname, false); |
||
| 61 | } |
||
| 62 | $this->dialogProvider->logTask("Detecting the project type"); |
||
| 63 | $type = $this->detectProjectType($projectname, $hostname); |
||
| 64 | |||
| 65 | $excludes = array( |
||
| 66 | ".composer", |
||
| 67 | "apachelogs/*", |
||
| 68 | "resizedcache/*", |
||
| 69 | "nobackup/*", |
||
| 70 | "tmp/*", |
||
| 71 | ".viminfo", |
||
| 72 | ".ssh", |
||
| 73 | ".bash_history", |
||
| 74 | ".config", |
||
| 75 | ".cache", |
||
| 76 | ".mysql_history", |
||
| 77 | "data/current/app/logs/*", |
||
| 78 | "data/current/var/logs/*", |
||
| 79 | "data/current/app/cache/*", |
||
| 80 | "data/current/var/cache/*", |
||
| 81 | ); |
||
| 82 | |||
| 83 | if (!$this->fileSystemProvider->projectExists($projectname)) { |
||
| 84 | $this->dialogProvider->logStep("Running the full rsync commands since " . $projectname . " is not on this computer"); |
||
| 85 | $fullExcludes = $excludes; |
||
| 86 | $fullExcludes[] = "data/shared"; |
||
| 87 | $fullExcludes[] = "data/builds"; |
||
| 88 | $fullExcludes[] = "data/releases"; |
||
| 89 | if ($type !== self::TYPE_JAVA) { |
||
| 90 | $fullExcludes[] = "data/" . $projectname; |
||
| 91 | } |
||
| 92 | $this->fetchFolder( |
||
| 93 | $this->app["config"]["projects"]["path"] . '/', |
||
| 94 | $hostname, |
||
| 95 | $this->app["config"]["remote_projects"]["path"]. "/" . $projectname, |
||
| 96 | $fullExcludes, |
||
| 97 | true |
||
| 98 | ); |
||
| 99 | |||
| 100 | if ($type !== self::TYPE_JAVA) { |
||
| 101 | $mvCommand = "mv " . $this->fileSystemProvider->getProjectDirectory($projectname) . "/data/current " . $this->fileSystemProvider->getProjectDirectory($projectname) . "/data/" . $projectname; |
||
| 102 | $this->processProvider->executeCommand($mvCommand); |
||
| 103 | } |
||
| 104 | if (file_exists($this->fileSystemProvider->getProjectDirectory($projectname) . "/data/" . $projectname)) { |
||
| 105 | $this->dialogProvider->logStep("Getting git repo data and try resetting to the master branch"); |
||
| 106 | $this->processProvider->executeCommand("cd ".$this->fileSystemProvider->getProjectDirectory($projectname) . "/data/" . $projectname. "; git pull 2>/dev/null; git fetch origin && git reset --hard && git clean -f -d && git checkout master", true); |
||
| 107 | } |
||
| 108 | } else { |
||
| 109 | $this->dialogProvider->logStep("Running the update rsync commands since " . $projectname . " already is on this computer"); |
||
| 110 | $updateExcludes = $excludes; |
||
| 111 | $updateExcludes[] = "data/*"; |
||
| 112 | |||
| 113 | $this->fetchFolderIfExists( |
||
| 114 | $this->fileSystemProvider->getProjectDirectory($projectname). '/', |
||
| 115 | $hostname, |
||
| 116 | "/home/projects/" . $projectname . '/*', |
||
| 117 | $updateExcludes |
||
| 118 | ); |
||
| 119 | |||
| 120 | $this->fetchFolderIfExists( |
||
| 121 | $this->fileSystemProvider->getProjectDirectory($projectname) . "/data/" . $projectname . "/web/uploads/", |
||
| 122 | $hostname, |
||
| 123 | "/home/projects/" . $projectname . "/data/current/web/uploads/*", |
||
| 124 | $updateExcludes |
||
| 125 | ); |
||
| 126 | |||
| 127 | $this->fetchFolderIfExists( |
||
| 128 | $this->fileSystemProvider->getProjectDirectory($projectname) . "/data/" . $projectname . "/sites/default/files/", |
||
| 129 | $hostname, |
||
| 130 | "/home/projects/" . $projectname . "/data/current/sites/default/files/*", |
||
| 131 | $updateExcludes |
||
| 132 | ); |
||
| 133 | if (file_exists($this->fileSystemProvider->getProjectDirectory($projectname) . "/data/" . $projectname) && $this->processProvider->executeCommand("cd ".$this->fileSystemProvider->getProjectDirectory($projectname) . "/data/" . $projectname. "; git status", true)===false) { |
||
| 134 | if($this->dialogProvider->askConfirmation("It looks like your source repo is broken, can I try reset this to master? [Y,n]")){ |
||
| 135 | $this->processProvider->executeCommand("cd ".$this->fileSystemProvider->getProjectDirectory($projectname) . "/data/" . $projectname. "; git pull 2>/dev/null; git fetch origin && git branch master origin/master && git reset --hard && git clean -f -d && git checkout master", true); |
||
| 136 | } |
||
| 137 | } |
||
| 138 | } |
||
| 139 | |||
| 140 | if (file_exists($this->fileSystemProvider->getProjectDirectory($projectname) . "/data/" . $projectname . '/.skylab/conf') && is_link($this->fileSystemProvider->getProjectDirectory($projectname) . '/conf')) { |
||
| 141 | $this->processProvider->executeSudoCommand("ln -sf " . $this->fileSystemProvider->getProjectDirectory($projectname) . "/data/" . $projectname . '/.skylab/conf ' . $this->fileSystemProvider->getProjectDirectory($projectname).'/conf'); |
||
| 142 | } |
||
| 143 | |||
| 144 | $project = $this->projectConfigProvider->loadProjectConfig($projectname); |
||
| 145 | $project['dir'] = $this->app["config"]["projects"]["path"] . $projectname; |
||
| 146 | $this->projectConfigProvider->writeProjectConfig($project); |
||
| 147 | |||
| 148 | if (!$this->input->getOption('no-database')) { |
||
| 149 | |||
| 150 | $this->dialogProvider->logStep("Dropping the databases"); |
||
| 151 | |||
| 152 | if( in_array('mysql', $this->skeletonProvider->getSkeletons() ) ) |
||
| 153 | { |
||
| 154 | $this->dialogProvider->logTask("Dropping the MySQL database"); |
||
| 155 | $dbh = new \PDO('mysql:host=localhost;', $this->app["config"]["mysql"]["user"], $this->app["config"]["mysql"]["password"]); |
||
| 156 | $dbh->query("DROP DATABASE IF EXISTS " . $projectname); |
||
| 157 | } |
||
| 158 | |||
| 159 | if( in_array('postgres', $this->skeletonProvider->getSkeletons() ) ) |
||
| 160 | { |
||
| 161 | $this->dialogProvider->logTask("Dropping the PostgreSQL database"); |
||
| 162 | $dbh = new \PDO( |
||
| 163 | $this->dialogProvider->logQuery( |
||
| 164 | 'pgsql:host=localhost;dbname=template1', |
||
| 165 | array( |
||
| 166 | "user" => $this->app["config"]["postgresql"]["user"], |
||
| 167 | "password" => $this->app["config"]["postgresql"]["password"] |
||
| 168 | ) |
||
| 169 | ), |
||
| 170 | $this->app["config"]["postgresql"]["user"], |
||
| 171 | $this->app["config"]["postgresql"]["password"] |
||
| 172 | ); |
||
| 173 | $dbh->query("DROP DATABASE IF EXISTS " . $projectname); |
||
| 174 | } |
||
| 175 | |||
| 176 | } |
||
| 177 | } |
||
| 178 | |||
| 248 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: