-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
read hyperlink for drawing image #490
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
EnclosureTest
example)
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. |
@@ -179,6 +185,15 @@ public function writeDrawing(XMLWriter $objWriter, BaseDrawing $pDrawing, $pRela | |||
$objWriter->writeAttribute('id', $pRelationId); | |||
$objWriter->writeAttribute('name', $pDrawing->getName()); | |||
$objWriter->writeAttribute('descr', $pDrawing->getDescription()); | |||
|
|||
//a:hlinkClick | |||
if ($pHlinkClickId >= 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, the if
should be extract to new private method.
$drawing->getHyperlink()->getUrl(), | ||
$drawing->getHyperlink()->isInternal() ? '' : 'External' | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scrutinizer has some suggestions how to fix this particular issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has not been addressed.
src/PhpSpreadsheet/Reader/Xlsx.php
Outdated
@@ -1606,6 +1613,14 @@ public function load($pFilename) | |||
$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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This if
must be extracted to a separate private method.
src/PhpSpreadsheet/Reader/Xlsx.php
Outdated
@@ -1654,6 +1670,14 @@ public function load($pFilename) | |||
$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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idem, extract to method.
/** | ||
* Image hyperlink. | ||
* | ||
* @var Hyperlink |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be @var null|Hyperlink
@@ -508,4 +516,24 @@ public function __clone() | |||
} | |||
} | |||
} | |||
|
|||
/** | |||
* @param Hyperlink $pHyperlink |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be @var null|Hyperlink
public function getHyperlink() | ||
{ | ||
if ($this->hyperlink === null) { | ||
$this->hyperlink = new Hyperlink(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you create new Hyperlink if it does not exist, instead of returning null
?
@@ -179,6 +185,15 @@ public function writeDrawing(XMLWriter $objWriter, BaseDrawing $pDrawing, $pRela | |||
$objWriter->writeAttribute('id', $pRelationId); | |||
$objWriter->writeAttribute('name', $pDrawing->getName()); | |||
$objWriter->writeAttribute('descr', $pDrawing->getDescription()); | |||
|
|||
//a:hlinkClick | |||
if ($pHlinkClickId >= 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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()->getUrl(), | ||
$drawing->getHyperlink()->isInternal() ? '' : 'External' | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has not been addressed.
<td></td> | ||
<td></td> | ||
<td></td> | ||
<td>$Drawing->getHyperlink()->getUrl($url)</td> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"$Drawing" should be "$drawing"
*/ | ||
public function getTypeHyperlink() | ||
{ | ||
return ($this->isInternal()) ? '' : 'External'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inverse condition and return early if no link
* | ||
* @throws WriterException | ||
*/ | ||
private function writeDrawingHyperLink($objWriter, $drawing, &$i) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a variable in the method to avoid public visibility.
@@ -1,19 +0,0 @@ | |||
<?php |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file and without_cell_reference.xlsx
should probably not be deleted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry
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