SierraTecnologia /
fabrica
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Rotinas de Inclusão de Dados |
||
| 4 | */ |
||
| 5 | |||
| 6 | namespace Fabrica\Tools\Software; |
||
| 7 | |||
| 8 | |||
| 9 | /** |
||
| 10 | * Header file |
||
| 11 | */ |
||
| 12 | use PhpOffice\PhpProject\Autoloader; |
||
| 13 | use PhpOffice\PhpProject\IOFactory; |
||
| 14 | |||
| 15 | error_reporting(E_ALL); |
||
| 16 | define('CLI', (PHP_SAPI == 'cli') ? true : false); |
||
| 17 | define('EOL', CLI ? PHP_EOL : '<br />'); |
||
| 18 | define('SCRIPT_FILENAME', basename($_SERVER['SCRIPT_FILENAME'], '.php')); |
||
| 19 | define('IS_INDEX', SCRIPT_FILENAME == 'index'); |
||
| 20 | |||
| 21 | require_once __DIR__ . '/../src/PhpProject/Autoloader.php'; |
||
| 22 | Autoloader::register(); |
||
| 23 | |||
| 24 | class FilePrograms |
||
| 25 | { |
||
| 26 | public function __construct($file) |
||
|
0 ignored issues
–
show
|
|||
| 27 | { |
||
| 28 | |||
| 29 | } |
||
| 30 | |||
| 31 | public function getRequirements() |
||
| 32 | { |
||
| 33 | return array( |
||
| 34 | 'php' => array('PHP 5.3.0', version_compare(phpversion(), '5.3.0', '>=')), |
||
| 35 | 'xml' => array('PHP extension XML', extension_loaded('xml')), |
||
| 36 | 'zip' => array('PHP extension ZipArchive (optional)', extension_loaded('zip')), |
||
| 37 | 'xmlw' => array('PHP extension XMLWriter (optional)', extension_loaded('xmlwriter')), |
||
| 38 | ); |
||
| 39 | } |
||
| 40 | |||
| 41 | public function getExtension($extension) |
||
| 42 | { |
||
| 43 | $returnWrites = []; |
||
| 44 | $types = $this->getTypes; |
||
|
0 ignored issues
–
show
The property
getTypes does not exist. Did you maybe forget to declare it?
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code: class MyClass { }
$x = new MyClass();
$x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: class MyClass {
public $foo;
}
$x = new MyClass();
$x->foo = true;
Loading history...
|
|||
| 45 | foreach($types as $type) { |
||
| 46 | $writes = (new $type)->getWrites($class, $type); |
||
|
0 ignored issues
–
show
|
|||
| 47 | foreach ($writes as $writerNameClass=>$extensionWriterClass) |
||
| 48 | { |
||
| 49 | if ($extensionWriterClass==$extension) { |
||
| 50 | if (!isset($returnWrites[$type])) { |
||
| 51 | $returnWrites[$type] = []; |
||
| 52 | } |
||
| 53 | $returnWrites[$type][] = $writerNameClass; |
||
| 54 | } |
||
| 55 | } |
||
| 56 | } |
||
| 57 | return $returnWrites; |
||
| 58 | } |
||
| 59 | |||
| 60 | public function getTypes() |
||
| 61 | { |
||
| 62 | return [ |
||
| 63 | Types\Project::class |
||
| 64 | ]; |
||
| 65 | } |
||
| 66 | |||
| 67 | public function run() |
||
| 68 | { |
||
| 69 | $this->header(); |
||
| 70 | $this->getRequirements(); |
||
| 71 | if (!CLI) { |
||
| 72 | ?> |
||
| 73 | <div class="jumbotron"> |
||
| 74 | <p>Welcome to PHPProject, a library written in pure PHP that provides a set of classes to write to and read from different document file formats, i.e. GanttProject (.gan) and MS Project (.mpx).</p> |
||
| 75 | <p> </p> |
||
| 76 | <p> |
||
| 77 | <a class="btn btn-lg btn-primary" href="https://github.com/PHPOffice/PHPProject" role="button"><i class="fa fa-github fa-lg" title="GitHub"></i> Fork us on Github!</a> |
||
| 78 | <a class="btn btn-lg btn-primary" href="http://phpproject.readthedocs.org/en/develop/" role="button"><i class="fa fa-book fa-lg" title="Docs"></i> Read the Docs</a> |
||
| 79 | </p> |
||
| 80 | </div> |
||
| 81 | <?php |
||
| 82 | } |
||
| 83 | if (!CLI) { |
||
| 84 | echo "<h3>Requirement check:</h3>"; |
||
| 85 | echo "<ul>"; |
||
| 86 | foreach ($requirements as $key => $value) { |
||
|
0 ignored issues
–
show
The variable
$requirements does not exist. Did you forget to declare it?
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug. Loading history...
|
|||
| 87 | list($label, $result) = $value; |
||
| 88 | $status = $result ? 'passed' : 'failed'; |
||
| 89 | echo "<li>{$label} ... <span class='{$status}'>{$status}</span></li>"; |
||
| 90 | } |
||
| 91 | echo "</ul>"; |
||
| 92 | include_once 'Sample_Footer.php'; |
||
| 93 | } else { |
||
| 94 | echo 'Requirement check:' . PHP_EOL; |
||
| 95 | foreach ($requirements as $key => $value) { |
||
| 96 | list($label, $result) = $value; |
||
| 97 | $status = $result ? '32m passed' : '31m failed'; |
||
| 98 | echo "{$label} ... \033[{$status}\033[0m" . PHP_EOL; |
||
| 99 | } |
||
| 100 | } |
||
| 101 | |||
| 102 | |||
| 103 | } |
||
| 104 | View Code Duplication | public function reader() |
|
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 105 | { |
||
| 106 | // Create new PHPProject object |
||
| 107 | echo date('H:i:s') . ' Create new PHPProject object'.EOL; |
||
| 108 | |||
| 109 | $objReader = IOFactory::createReader('GanttProject'); |
||
| 110 | $objPHPProject = $objReader->load($this->file->getTmp()); |
||
|
0 ignored issues
–
show
The property
file does not exist. Did you maybe forget to declare it?
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code: class MyClass { }
$x = new MyClass();
$x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: class MyClass {
public $foo;
}
$x = new MyClass();
$x->foo = true;
Loading history...
|
|||
| 111 | |||
| 112 | // Set properties |
||
| 113 | echo date('H:i:s') . ' Get properties'.EOL; |
||
| 114 | echo 'Creator > '.$objPHPProject->getProperties()->getCreator().EOL; |
||
| 115 | echo 'LastModifiedBy > '.$objPHPProject->getProperties()->getLastModifiedBy().EOL; |
||
| 116 | echo 'Title > '.$objPHPProject->getProperties()->getTitle().EOL; |
||
| 117 | echo 'Subject > '.$objPHPProject->getProperties()->getSubject().EOL; |
||
| 118 | echo 'Description > '.$objPHPProject->getProperties()->getDescription().EOL; |
||
| 119 | echo EOL; |
||
| 120 | // Add some data |
||
| 121 | echo date('H:i:s') . ' Get some data'.EOL; |
||
| 122 | echo 'StartDate > '.$objPHPProject->getInformations()->getStartDate().EOL; |
||
| 123 | echo 'EndDate > '.$objPHPProject->getInformations()->getEndDate().EOL; |
||
| 124 | echo EOL; |
||
| 125 | // Ressources |
||
| 126 | echo date('H:i:s') . ' Get ressources'.EOL; |
||
| 127 | foreach ($objPHPProject->getAllResources() as $oResource){ |
||
| 128 | echo 'Resource : '.$oResource->getTitle().EOL; |
||
| 129 | } |
||
| 130 | echo EOL; |
||
| 131 | // Tasks |
||
| 132 | echo date('H:i:s') . ' Get tasks'.EOL; |
||
| 133 | foreach ($objPHPProject->getAllTasks() as $oTask){ |
||
| 134 | echoTask($objPHPProject, $oTask); |
||
| 135 | } |
||
| 136 | // Echo done |
||
| 137 | echo date('H:i:s') . ' Done reading file.'.EOL; |
||
| 138 | if (!CLI) { |
||
| 139 | include_once 'Sample_Footer.php'; |
||
| 140 | } |
||
| 141 | } |
||
| 142 | |||
| 143 | public function header() |
||
| 144 | { |
||
| 145 | |||
| 146 | // Set writers |
||
| 147 | $writers = $this->getWrites(); |
||
|
0 ignored issues
–
show
The method
getWrites() does not seem to exist on object<Fabrica\Tools\Software\FilePrograms>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
$writers is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 148 | |||
| 149 | // Return to the caller script when runs by CLI |
||
| 150 | if (CLI) { |
||
| 151 | return; |
||
| 152 | } |
||
| 153 | |||
| 154 | // Set titles and names |
||
| 155 | $pageHeading = str_replace('_', ' ', SCRIPT_FILENAME); |
||
| 156 | $pageTitle = IS_INDEX ? 'Welcome to ' : "{$pageHeading} - "; |
||
| 157 | $pageTitle .= 'PHPProject'; |
||
| 158 | $pageHeading = IS_INDEX ? '' : "<h1>{$pageHeading}</h1>"; |
||
| 159 | |||
| 160 | // Populate samples |
||
| 161 | $files = ''; |
||
| 162 | if ($handle = opendir('.')) { |
||
| 163 | while (false !== ($file = readdir($handle))) { |
||
| 164 | if (preg_match('/^Sample_\d+_/', $file)) { |
||
| 165 | $name = str_replace('_', ' ', preg_replace('/(Sample_|\.php)/', '', $file)); |
||
| 166 | $files .= "<li><a href='{$file}'>{$name}</a></li>"; |
||
| 167 | } |
||
| 168 | } |
||
| 169 | closedir($handle); |
||
| 170 | } |
||
| 171 | |||
| 172 | ?> |
||
| 173 | <title><?php echo $pageTitle; ?></title> |
||
| 174 | <meta charset="utf-8"> |
||
| 175 | <meta http-equiv="X-UA-Compatible" content="IE=edge" /> |
||
| 176 | <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
||
| 177 | <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css" /> |
||
| 178 | <link rel="stylesheet" href="bootstrap/css/font-awesome.min.css" /> |
||
| 179 | <link rel="stylesheet" href="bootstrap/css/phppowerpoint.css" /> |
||
| 180 | </head> |
||
| 181 | <body> |
||
| 182 | <div class="container"> |
||
| 183 | <div class="navbar navbar-default" role="navigation"> |
||
| 184 | <div class="container-fluid"> |
||
| 185 | <div class="navbar-header"> |
||
| 186 | <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> |
||
| 187 | <span class="sr-only">Toggle navigation</span> |
||
| 188 | <span class="icon-bar"></span> |
||
| 189 | <span class="icon-bar"></span> |
||
| 190 | <span class="icon-bar"></span> |
||
| 191 | </button> |
||
| 192 | <a class="navbar-brand" href="./">PHPProject</a> |
||
| 193 | </div> |
||
| 194 | <div class="navbar-collapse collapse"> |
||
| 195 | <ul class="nav navbar-nav"> |
||
| 196 | <li class="dropdown active"> |
||
| 197 | <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-code fa-lg"></i> Samples<strong class="caret"></strong></a> |
||
| 198 | <ul class="dropdown-menu"><?php echo $files; ?></ul> |
||
| 199 | </li> |
||
| 200 | </ul> |
||
| 201 | <ul class="nav navbar-nav navbar-right"> |
||
| 202 | <li><a href="https://github.com/PHPOffice/PHPProject"><i class="fa fa-github fa-lg" title="GitHub"></i> </a></li> |
||
| 203 | <li><a href="http://phpproject.readthedocs.org/en/develop/"><i class="fa fa-book fa-lg" title="Docs"></i> </a></li> |
||
| 204 | <li><a href="http://twitter.com/PHPOffice"><i class="fa fa-twitter fa-lg" title="Twitter"></i> </a></li> |
||
| 205 | </ul> |
||
| 206 | </div> |
||
| 207 | </div> |
||
| 208 | </div> |
||
| 209 | <?php echo $pageHeading; ?> |
||
| 210 | <?php |
||
| 211 | } |
||
| 212 | |||
| 213 | /** |
||
| 214 | * Write documents |
||
| 215 | * |
||
| 216 | * @param \PhpOffice\PhpWord\PhpWord $phpWord |
||
|
0 ignored issues
–
show
There is no parameter named
$phpWord. Was it maybe removed?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. Consider the following example. The parameter /**
* @param array $germany
* @param array $island
* @param array $italy
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was removed, but the annotation was not. Loading history...
|
|||
| 217 | * @param string $filename |
||
| 218 | * @param array $writers |
||
| 219 | */ |
||
| 220 | function write($phpPowerPoint, $filename, $writers) |
||
| 221 | { |
||
| 222 | $result = ''; |
||
| 223 | |||
| 224 | // Write documents |
||
| 225 | foreach ($writers as $writer => $extension) { |
||
| 226 | $result .= date('H:i:s') . " Write to {$writer} format"; |
||
| 227 | if (!is_null($extension)) { |
||
| 228 | $xmlWriter = IOFactory::createWriter($phpPowerPoint, $writer); |
||
| 229 | $xmlWriter->save(__DIR__ . DIRECTORY_SEPARATOR."{$filename}.{$extension}"); |
||
| 230 | rename(__DIR__ . "/{$filename}.{$extension}", __DIR__ . "/results/{$filename}.{$extension}"); |
||
| 231 | } else { |
||
| 232 | $result .= ' ... NOT DONE!'; |
||
| 233 | } |
||
| 234 | $result .= EOL; |
||
| 235 | } |
||
| 236 | |||
| 237 | $result .= getEndingNotes($writers); |
||
| 238 | |||
| 239 | return $result; |
||
| 240 | } |
||
| 241 | |||
| 242 | /** |
||
| 243 | * Get ending notes |
||
| 244 | * |
||
| 245 | * @param array $writers |
||
| 246 | */ |
||
| 247 | function getEndingNotes($writers) |
||
| 248 | { |
||
| 249 | $result = ''; |
||
| 250 | |||
| 251 | // Do not show execution time for index |
||
| 252 | if (!IS_INDEX) { |
||
| 253 | $result .= date('H:i:s') . " Done writing file(s)" . EOL; |
||
| 254 | $result .= date('H:i:s') . " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB" . EOL; |
||
| 255 | } |
||
| 256 | |||
| 257 | // Return |
||
| 258 | if (CLI) { |
||
| 259 | $result .= 'The results are stored in the "results" subdirectory.' . EOL; |
||
| 260 | } else { |
||
| 261 | if (!IS_INDEX) { |
||
| 262 | $types = array_values($writers); |
||
| 263 | $result .= '<p> </p>'; |
||
| 264 | $result .= '<p>Results: '; |
||
| 265 | foreach ($types as $type) { |
||
| 266 | if (!is_null($type)) { |
||
| 267 | $resultFile = 'results/' . SCRIPT_FILENAME . '.' . $type; |
||
| 268 | if (file_exists($resultFile)) { |
||
| 269 | $result .= "<a href='{$resultFile}' class='btn btn-primary'>{$type}</a> "; |
||
| 270 | } |
||
| 271 | } |
||
| 272 | } |
||
| 273 | $result .= '</p>'; |
||
| 274 | } |
||
| 275 | } |
||
| 276 | |||
| 277 | return $result; |
||
| 278 | } |
||
| 279 | |||
| 280 | function echoTask($oPHPProject, $oTask, $level = 0) |
||
| 281 | { |
||
| 282 | echo '<strong>'.str_repeat('>', 2 * $level).' Task : '.$oTask->getName().'</strong>'.EOL; |
||
| 283 | echo ' '.str_repeat('>', 2 * ($level + 1)).' Duration : '.$oTask->getDuration().EOL; |
||
| 284 | echo ' '.str_repeat('>', 2 * ($level + 1)).' StartDate : '.date('Y-m-d', $oTask->getStartDate()).EOL; |
||
| 285 | echo ' '.str_repeat('>', 2 * ($level + 1)).' Progress : '.$oTask->getProgress().EOL; |
||
| 286 | echo ' '.str_repeat('>', 2 * ($level + 1)).' Resources : '.EOL; |
||
| 287 | $oTaskResources = $oTask->getResources(); |
||
| 288 | if(!empty($oTaskResources)) { |
||
| 289 | foreach ($oTaskResources as $oResource){ |
||
| 290 | echo ' '.str_repeat('>', 2 * ($level + 2)).' Resource : '.$oResource->getTitle().EOL; |
||
| 291 | } |
||
| 292 | } |
||
| 293 | echo EOL; |
||
| 294 | $level++; |
||
| 295 | if($oTask->getTaskCount() > 0) { |
||
| 296 | foreach ($oTask->getTasks() as $oSubTask){ |
||
| 297 | echoTask($oPHPProject, $oSubTask, $level); |
||
| 298 | } |
||
| 299 | } |
||
| 300 | $level--; |
||
| 301 | } |
||
| 302 | } |
||
| 303 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.