-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Add background color support for text box element for Word writer #2364
Conversation
src/PhpWord/Style/TextBox.php
Outdated
/** | ||
* background color. | ||
* | ||
* @var string |
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.
* @var string | |
* @var string|null |
src/PhpWord/Style/TextBox.php
Outdated
* | ||
* @param string $value | ||
*/ | ||
public function setBgColor($value = null): void |
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.
public function setBgColor($value = null): void | |
public function setBgColor(string $value = null): self |
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.
Return $this in a setter method is not used in any other styling class' setter method. Doing this for only one class or even worser for only one class method is very inconsistent. I think this should be changed for all setters in version 1.1.x.
src/PhpWord/Style/TextBox.php
Outdated
/** | ||
* Set background color. | ||
* | ||
* @param string $value |
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.
* @param string $value | |
* @param string $value | |
* @return self |
src/PhpWord/Style/TextBox.php
Outdated
* | ||
* @return string | ||
*/ | ||
public function getBgColor() |
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.
public function getBgColor() | |
public function getBgColor(): ?string |
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.
@hazington Some feedbacks to apply before merge
@hazington Do you think you can add unit tests ? |
Yes, I can cover this code with an unit test. By the way, this code is based on version 0.18.x and copied from another style element of PHPWord that already supported setting the background color. So this is not my coding style, it simply followed the old project's style. I appreciate your feedback as I personally prefer coding in PHP 8.1, with strict_types=1 and based on PSR-12. By any chance, is refactoring based on PSR-12 and at least strong typed coding on the road map? That would make supporting PHPWord so much easier! :) |
So, the requested unit tests have been added and the code style fixed according to the php-cs-fixer configuration by running the fix script from composer.json. |
I've some trouble with the PHP 7.1 and PHP 7.2 coverage. Using "assertRegExp" will fail the CI / coverage and using the "assertMatchesRegularExpression" will let the coverage for PHP 7.1 and 7.2 fail. Any solution here? Since PHP 7.4 is officially EOL, dropping coverage for at least PHP 7.1, 7.2 and 7.3 should be considered. |
This workaround seems to solve the CI coverage issue: // Try to address CI coverage issue for PHP 7.1 and 7.2 when using regex match assertions
if (method_exists(static::class, 'assertRegExp')) {
self::assertRegExp('/z\-index:\-[0-9]*/', $style);
} else {
self::assertMatchesRegularExpression('/z\-index:\-[0-9]*/', $style);
} |
Thanks @hazington for your contribution |
Description
It is now possible to fill the background color of text box elements (only Word2007 writer!). There is no documentation for the Textbox element, so I can't add the changes.
Fixes # (issue)
No bugfix.
Checklist:
composer run-script check --timeout=0
and no errors were reported