read hyperlink for drawing image#490
read hyperlink for drawing image#490tezrik wants to merge 19 commits intoPHPOffice:developfrom tezrik:develop
Conversation
There was a problem hiding this comment.
This looks like an interesting contribution, but it misses a few things to be merged. Could you take care of it ?
- add write support for symetry
- document feature in docs/references/features-cross-reference.md
- cover with unit tests (see
EnclosureTestexample)
|
sorry in my English |
|
I think I had a problem. I can not understand the error. Please help me |
|
The error is that some of the methods you changed no longer pass code quality checks. |
| $objWriter->writeAttribute('descr', $pDrawing->getDescription()); | ||
|
|
||
| //a:hlinkClick | ||
| if ($pHlinkClickId >= 0) { |
There was a problem hiding this comment.
This if increases the "Condition count" from 6 to 7, which raised the rating from B to C.
The project's current configuration of Scrutinizer forbids ratings above or equal to C.
There was a problem hiding this comment.
There was a problem hiding this comment.
Indeed, the if should be extract to new private method.
| $drawing->getHyperlink()->isInternal() ? '' : 'External' | ||
| ); | ||
| } | ||
| } |
There was a problem hiding this comment.
The if and the ?: here raise the "Condition count" from 8 to 10 and together with the added lines themselves raised the rating from B to C.
Scrutinizer about Rels::writeDrawingRelationships().
There was a problem hiding this comment.
Scrutinizer has some suggestions how to fix this particular issue.
There was a problem hiding this comment.
Again the entire if should go into a new private method (even if it's short). Something like writeDrawingHyperLink(XMLWriter $objWriter, BaseDrawing $drawing)
|
If you are not sure how to fix the issues, wait for PowerKiki's comments about your further changes. |
|
Thank you for the clarification. I expect then a response from PowerKiki's |
PowerKiKi
left a comment
There was a problem hiding this comment.
Thanks you for the modifications. The test and doc look good. There is a few things that can improve the code quality before merging. Please have a look.
| require __DIR__ . '/../Header.php'; | ||
|
|
||
| $inputFileType = 'Xlsx'; | ||
| $inputFileName = __DIR__ . '/sampleData/example3.xlsx'; |
There was a problem hiding this comment.
We try to avoid adding XLSX files when possible to avoid growing the size of the repository. So please delete samples/Reader/sampleData/example3.xlsx, and either change the sample to write and read, or delete the sample entirely (but do not keep it with only read).
src/PhpSpreadsheet/Reader/Xlsx.php
Outdated
| $shadow->getColor()->setRGB(self::getArrayItem($outerShdw->srgbClr->attributes(), 'val')); | ||
| $shadow->setAlpha(self::getArrayItem($outerShdw->srgbClr->alpha->attributes(), 'val') / 1000); | ||
| } | ||
| if ($hlinkClick) { |
There was a problem hiding this comment.
This if must be extracted to a separate private method.
src/PhpSpreadsheet/Reader/Xlsx.php
Outdated
| $shadow->getColor()->setRGB(self::getArrayItem($outerShdw->srgbClr->attributes(), 'val')); | ||
| $shadow->setAlpha(self::getArrayItem($outerShdw->srgbClr->alpha->attributes(), 'val') / 1000); | ||
| } | ||
| if ($hlinkClick) { |
| /** | ||
| * Image hyperlink. | ||
| * | ||
| * @var Hyperlink |
There was a problem hiding this comment.
This should be @var null|Hyperlink
| } | ||
|
|
||
| /** | ||
| * @param Hyperlink $pHyperlink |
There was a problem hiding this comment.
This should be @var null|Hyperlink
| public function getHyperlink() | ||
| { | ||
| if ($this->hyperlink === null) { | ||
| $this->hyperlink = new Hyperlink(); |
There was a problem hiding this comment.
Why do you create new Hyperlink if it does not exist, instead of returning null ?
| $objWriter->writeAttribute('descr', $pDrawing->getDescription()); | ||
|
|
||
| //a:hlinkClick | ||
| if ($pHlinkClickId >= 0) { |
There was a problem hiding this comment.
Indeed, the if should be extract to new private method.
| * @throws WriterException | ||
| */ | ||
| public function writeDrawing(XMLWriter $objWriter, BaseDrawing $pDrawing, $pRelationId = -1) | ||
| public function writeDrawing(XMLWriter $objWriter, BaseDrawing $pDrawing, $pRelationId = -1, $pHlinkClickId = -1) |
There was a problem hiding this comment.
Let's use null instead of -1 for a better semantic of absence of value. Then we should also change @param null|int $pHlinkClickId.
| $drawing->getHyperlink()->isInternal() ? '' : 'External' | ||
| ); | ||
| } | ||
| } |
There was a problem hiding this comment.
Again the entire if should go into a new private method (even if it's short). Something like writeDrawingHyperLink(XMLWriter $objWriter, BaseDrawing $drawing)
| * User: yuzhakov | ||
| * Date: 08.05.18 | ||
| * Time: 12:00. | ||
| */ |
There was a problem hiding this comment.
We do not use file comment blocks, please remove. You will be credited in the commit information.
|
Ok, I'll try to do it in the near future. |
|
Sorry, but I can not understand how these tests are related to me. In my changes there are none. |
PowerKiKi
left a comment
There was a problem hiding this comment.
There are still a few things to change in code.
I restarted the test job, let's see if it passes...
| require __DIR__ . '/../Header.php'; | ||
|
|
||
| $inputFileType = 'Xlsx'; | ||
| $inputFileName = __DIR__ . '/sampleData/example3.xlsx'; |
| <td></td> | ||
| <td></td> | ||
| <td></td> | ||
| <td>$Drawing->getHyperlink()->getUrl($url)</td> |
There was a problem hiding this comment.
"$Drawing" should be "$drawing"
| */ | ||
| public function getTypeHyperlink() | ||
| { | ||
| return ($this->isInternal()) ? '' : 'External'; |
There was a problem hiding this comment.
extra parenthesis should be removed
src/PhpSpreadsheet/Reader/Xlsx.php
Outdated
| * @param \SimpleXMLElement $cellAnchor | ||
| * @param array $hyperlinks | ||
| */ | ||
| private function readHyperLinkDrawing(&$objDrawing, $cellAnchor, $hyperlinks) |
There was a problem hiding this comment.
Parameters must be type hinted. Also "&$objDrawing" must be "$objDrawing"
src/PhpSpreadsheet/Reader/Xlsx.php
Outdated
| private function readHyperLinkDrawing(&$objDrawing, $cellAnchor, $hyperlinks) | ||
| { | ||
| $hlinkClick = $cellAnchor->pic->nvPicPr->cNvPr->children('http://schemas.openxmlformats.org/drawingml/2006/main')->hlinkClick; | ||
| if ($hlinkClick) { |
There was a problem hiding this comment.
Inverse the condition to return early if there is no link
| */ | ||
| private function writeHyperLinkDriwing(XMLWriter &$objWriter, $pHlinkClickId) | ||
| { | ||
| if ($pHlinkClickId !== null) { |
There was a problem hiding this comment.
Inverse condition and return early if no link
| */ | ||
| private function writeDrawingHyperLink($objWriter, $drawing, &$i) | ||
| { | ||
| if ($drawing->getHyperlink() !== null) { |
There was a problem hiding this comment.
Inverse condition and return early if no link
| * | ||
| * @throws WriterException | ||
| */ | ||
| private function writeDrawingHyperLink($objWriter, $drawing, &$i) |
There was a problem hiding this comment.
Parameters should be typed and &$i should be avoided and instead use return value.
|
|
||
| class DrawingImageHyperlinkTest extends AbstractFunctional | ||
| { | ||
| const BASE_URL = 'https://github.com/PHPOffice/PhpSpreadsheet'; |
There was a problem hiding this comment.
This should be a variable in the method to avoid public visibility.
| @@ -1,19 +0,0 @@ | |||
| <?php | |||
There was a problem hiding this comment.
This file and without_cell_reference.xlsx should probably not be deleted
|
Hi, I ran tests on the local machine. All tests pass without errors. |
|
Thanks ! I merged it. |
This is:
Checklist:
Why this change is needed?
Read hyperlinks for drawing image