Skip to content
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

Merged
merged 10 commits into from
Jan 4, 2023

Conversation

hazington
Copy link
Contributor

@hazington hazington commented Dec 30, 2022

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:

  • I have run composer run-script check --timeout=0 and no errors were reported
  • The new code is covered by unit tests (check build/coverage for coverage report)
  • I have updated the documentation to describe the changes

/**
* background color.
*
* @var string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @var string
* @var string|null

*
* @param string $value
*/
public function setBgColor($value = null): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function setBgColor($value = null): void
public function setBgColor(string $value = null): self

Copy link
Contributor Author

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.

/**
* Set background color.
*
* @param string $value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param string $value
* @param string $value
* @return self

*
* @return string
*/
public function getBgColor()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function getBgColor()
public function getBgColor(): ?string

Copy link
Member

@Progi1984 Progi1984 left a 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

@Progi1984
Copy link
Member

@hazington Do you think you can add unit tests ?

@hazington
Copy link
Contributor Author

@Progi1984

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! :)

@hazington
Copy link
Contributor Author

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.

@hazington
Copy link
Contributor Author

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.

679a738

@hazington
Copy link
Contributor Author

This workaround seems to solve the CI coverage issue:

53d34fd

        // 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);
        }

@Progi1984 Progi1984 added this to the v1.1.0 milestone Jan 4, 2023
@Progi1984 Progi1984 merged commit a379577 into PHPOffice:master Jan 4, 2023
@Progi1984
Copy link
Member

Progi1984 commented Jan 4, 2023

Thanks @hazington for your contribution

@Progi1984 Progi1984 mentioned this pull request Sep 14, 2023
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants