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

confusing setXXXStyle methods #555

Closed
RKaczmarek opened this issue Jun 16, 2015 · 0 comments
Closed

confusing setXXXStyle methods #555

RKaczmarek opened this issue Jun 16, 2015 · 0 comments

Comments

@RKaczmarek
Copy link

RKaczmarek commented Jun 16, 2015

Hi,

im confused about the structure of style elements and the setXXXStyle methods. I hope I can describe it correctly.

I had a look at the Text element and will describe my problem with this class as example.

Writer
  • PhpWord/Writer/Word2007/Element/Text
    • writes text element to xml file
    • writes font element to xml file
    • does not write paragraph style of font element to xml file
Element
  • PhpWord/Element/Text
    • __construct
      • sets paragraph style
      • sets font style (setFontStyle)
    • setFontStyle
      • sets paragraph style again!!!
      • passes paragraph style to Font element (why? not used!)

Next point is, setFontStyle seems to be unstable.

public function setFontStyle($style = null, $paragraphStyle = null)
{
    if ($style instanceof Font) {
        $this->fontStyle = $style;
        $this->setParagraphStyle($paragraphStyle);
    } elseif (is_array($style)) {
        $this->fontStyle = new Font('text', $paragraphStyle);
        $this->fontStyle->setStyleByArray($style);
    } elseif (null === $style) {
        $this->fontStyle = new Font('text', $paragraphStyle);
    } else {
        // unstable!!!
        // $style could be an object of any other class or any other type of variable
        $this->fontStyle = $style;
        $this->setParagraphStyle($paragraphStyle);
    }

    return $this->fontStyle;
}

Maybe replace it with something like:

public function setFontStyle($style = null)
{
    if ($style instanceof Font || is_string($style)) {
        $this->fontStyle = $style;
    } elseif (is_array($style)) {
        $this->fontStyle = new Font('text');
        $this->fontStyle->setStyleByArray($style);
    } elseif ($style === null) {
        $this->fontStyle = new Font('text');
    } else {
        throw new \InvalidArgumentException("Invalid font style");
    }

    return $this->fontStyle;
}

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant