| 47 | | /** |
|---|
| 48 | | * File to be performed syntax check on |
|---|
| 49 | | * @param PhingFile $file |
|---|
| 50 | | */ |
|---|
| 51 | | public function setFile(PhingFile $file) { |
|---|
| 52 | | $this->file = $file; |
|---|
| 53 | | } |
|---|
| 54 | | |
|---|
| 55 | | /** |
|---|
| 56 | | * Nested creator, creates a FileSet for this task |
|---|
| 57 | | * |
|---|
| 58 | | * @return FileSet The created fileset object |
|---|
| 59 | | */ |
|---|
| 60 | | function createFileSet() { |
|---|
| 61 | | $num = array_push($this->filesets, new FileSet()); |
|---|
| 62 | | return $this->filesets[$num-1]; |
|---|
| 63 | | } |
|---|
| | 48 | /** |
|---|
| | 49 | * File to be performed syntax check on |
|---|
| | 50 | * @param PhingFile $file |
|---|
| | 51 | */ |
|---|
| | 52 | public function setFile(PhingFile $file) { |
|---|
| | 53 | $this->file = $file; |
|---|
| | 54 | } |
|---|
| 73 | | if($this->file instanceof PhingFile) { |
|---|
| 74 | | $this->lint($this->file->getPath()); |
|---|
| 75 | | } else { // process filesets |
|---|
| 76 | | $project = $this->getProject(); |
|---|
| 77 | | foreach($this->filesets as $fs) { |
|---|
| 78 | | $ds = $fs->getDirectoryScanner($project); |
|---|
| 79 | | $files = $ds->getIncludedFiles(); |
|---|
| 80 | | $dir = $fs->getDir($this->project)->getPath(); |
|---|
| 81 | | foreach($files as $file) { |
|---|
| 82 | | $this->lint($dir.DIRECTORY_SEPARATOR.$file); |
|---|
| 83 | | } |
|---|
| 84 | | } |
|---|
| 85 | | } |
|---|
| | 65 | /** |
|---|
| | 66 | * Nested creator, creates a FileSet for this task |
|---|
| | 67 | * |
|---|
| | 68 | * @return FileSet The created fileset object |
|---|
| | 69 | */ |
|---|
| | 70 | function createFileSet() { |
|---|
| | 71 | $num = array_push($this->filesets, new FileSet()); |
|---|
| | 72 | return $this->filesets[$num-1]; |
|---|
| | 73 | } |
|---|
| 90 | | /** |
|---|
| 91 | | * Performs the actual syntax check |
|---|
| 92 | | * |
|---|
| 93 | | * @param string $file |
|---|
| 94 | | * @return void |
|---|
| 95 | | */ |
|---|
| 96 | | protected function lint($file) { |
|---|
| 97 | | $command = 'php -l '; |
|---|
| 98 | | if(file_exists($file)) { |
|---|
| 99 | | if(is_readable($file)) { |
|---|
| 100 | | $message = array(); |
|---|
| 101 | | exec($command.$file, $message); |
|---|
| 102 | | if(!preg_match('/^No syntax errors detected/', $message[0])) { |
|---|
| 103 | | if (count($messages) > 1) |
|---|
| 104 | | { |
|---|
| 105 | | $this->log($message[1], Project::MSG_ERR); |
|---|
| 106 | | } |
|---|
| 107 | | else |
|---|
| 108 | | { |
|---|
| 109 | | $this->log("Could not parse file", Project::MSG_ERR); |
|---|
| 110 | | } |
|---|
| 111 | | |
|---|
| 112 | | $this->hasErrors = true; |
|---|
| 113 | | } else { |
|---|
| 114 | | $this->log($file.': No syntax errors detected', Project::MSG_INFO); |
|---|
| | 83 | if($this->file instanceof PhingFile) { |
|---|
| | 84 | $this->lint($this->file->getPath()); |
|---|
| | 85 | } else { // process filesets |
|---|
| | 86 | $project = $this->getProject(); |
|---|
| | 87 | foreach($this->filesets as $fs) { |
|---|
| | 88 | $ds = $fs->getDirectoryScanner($project); |
|---|
| | 89 | $files = $ds->getIncludedFiles(); |
|---|
| | 90 | $dir = $fs->getDir($this->project)->getPath(); |
|---|
| | 91 | foreach($files as $file) { |
|---|
| | 92 | $this->lint($dir.DIRECTORY_SEPARATOR.$file); |
|---|
| | 93 | } |
|---|
| | 94 | } |
|---|
| | 95 | } |
|---|
| | 96 | |
|---|
| | 97 | if ($this->haltOnFailure && $this->hasErrors) throw new BuildException('Syntax error(s) in PHP files'); |
|---|
| 116 | | } else { |
|---|
| 117 | | throw new BuildException('Permission denied: '.$file); |
|---|
| 118 | | } |
|---|
| 119 | | } else { |
|---|
| 120 | | throw new BuildException('File not found: '.$file); |
|---|
| 121 | | } |
|---|
| 122 | | } |
|---|
| | 99 | |
|---|
| | 100 | /** |
|---|
| | 101 | * Performs the actual syntax check |
|---|
| | 102 | * |
|---|
| | 103 | * @param string $file |
|---|
| | 104 | * @return void |
|---|
| | 105 | */ |
|---|
| | 106 | protected function lint($file) { |
|---|
| | 107 | $command = 'php -l '; |
|---|
| | 108 | if(file_exists($file)) { |
|---|
| | 109 | if(is_readable($file)) { |
|---|
| | 110 | $messages = array(); |
|---|
| | 111 | exec($command.$file, $messages); |
|---|
| | 112 | if(!preg_match('/^No syntax errors detected/', $messages[0])) { |
|---|
| | 113 | if (count($messages) > 1) { |
|---|
| | 114 | if ($this->errorProperty) { |
|---|
| | 115 | $this->project->setProperty($this->errorProperty, $messages[1]); |
|---|
| | 116 | } |
|---|
| | 117 | $this->log($messages[1], Project::MSG_ERR); |
|---|
| | 118 | } else { |
|---|
| | 119 | $this->log("Could not parse file", Project::MSG_ERR); |
|---|
| | 120 | } |
|---|
| | 121 | |
|---|
| | 122 | $this->hasErrors = true; |
|---|
| | 123 | |
|---|
| | 124 | } else { |
|---|
| | 125 | $this->log($file.': No syntax errors detected', Project::MSG_INFO); |
|---|
| | 126 | } |
|---|
| | 127 | } else { |
|---|
| | 128 | throw new BuildException('Permission denied: '.$file); |
|---|
| | 129 | } |
|---|
| | 130 | } else { |
|---|
| | 131 | throw new BuildException('File not found: '.$file); |
|---|
| | 132 | } |
|---|
| | 133 | } |
|---|