1 | <?php |
||
21 | class ArtifactAttachmentXMLZipper implements ArtifactAttachmentXMLExporter { |
||
22 | |||
23 | /** @var ArtifactXMLNodeHelper */ |
||
24 | private $node_helper; |
||
25 | |||
26 | /** @var ZipArchive */ |
||
27 | private $archive; |
||
28 | |||
29 | /** @var Boolean */ |
||
30 | private $skip_files = false; |
||
31 | |||
32 | /** @var ArtifactXMLExporterDao */ |
||
33 | private $dao; |
||
34 | |||
35 | public function __construct(ArtifactXMLNodeHelper $node_helper, ArtifactXMLExporterDao $dao, ZipArchive $archive, $skip_files) { |
||
36 | $this->node_helper = $node_helper; |
||
37 | $this->dao = $dao; |
||
38 | $this->archive = $archive; |
||
39 | $this->skip_files = $skip_files; |
||
40 | } |
||
41 | |||
42 | public function addFilesToArtifact(DOMElement $artifact_node, $artifact_type_id, $artifact_id) { |
||
43 | $dar = $this->dao->searchFilesForArtifact($artifact_id); |
||
44 | if (count($dar)) { |
||
45 | $this->archive->addEmptyDir(ArtifactXMLExporter::ARCHIVE_DATA_DIR); |
||
46 | } |
||
47 | foreach($dar as $row) { |
||
|
|||
48 | $xml_file_id = ArtifactAttachmentFieldXMLExporter::XML_FILE_PREFIX.$row['id']; |
||
49 | $path_in_archive = $this->getFilePathInArchive($xml_file_id); |
||
50 | if ($this->skip_files) { |
||
51 | $this->archive->addFromString($path_in_archive, ''); |
||
52 | } else { |
||
53 | $this->archive->addFile( |
||
54 | $this->getFilePathOnServer($artifact_type_id, $row['id']), |
||
55 | $path_in_archive |
||
56 | ); |
||
57 | } |
||
58 | $file = $this->node_helper->createElement('file'); |
||
59 | $file->setAttribute('id', $xml_file_id); |
||
60 | $file->appendChild($this->node_helper->getNodeWithValue('filename', $row['filename'])); |
||
61 | $file->appendChild($this->node_helper->getNodeWithValue('path', $this->getFilePathInArchive($xml_file_id))); |
||
62 | $file->appendChild($this->node_helper->getNodeWithValue('filesize', $row['filesize'])); |
||
63 | $file->appendChild($this->node_helper->getNodeWithValue('filetype', $row['filetype'])); |
||
64 | $file->appendChild($this->node_helper->getNodeWithValue('description', $row['description'])); |
||
65 | $artifact_node->appendChild($file); |
||
66 | } |
||
67 | } |
||
68 | |||
69 | private function getFilePathOnServer($artifact_type_id, $attachment_id) { |
||
72 | |||
73 | private function getFilePathInArchive($xml_file_id) { |
||
76 | } |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.