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

Element/Cell, Element/Row do not accept style objects in constructor, maybe others too #556

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

Comments

@RKaczmarek
Copy link

RKaczmarek commented Jun 16, 2015

Hi,

passing a Style/Cell object to the consctructor of Element/Cell ignores the object. A new Style/Cell object is always created.

In Element/Cell

public function __construct($width = null, $style = null)
{
    $this->width = $width;
    $this->style = $this->setNewStyle(new CellStyle(), $style, true);
}

should be changed to (not stable)

public function __construct($width = null, $style = null)
{
    $this->width = $width;
    $this->style = $this->setNewStyle(new CellStyle(), $style, !$style);
}

or better (stable parameter three)

public function __construct($width = null, $style = null)
{
    $this->width = $width;
    $this->style = $this->setNewStyle(new CellStyle(), $style, !($style instanceof CellStyle));
}

or best case (without using $this->setNewStyle)

public function __construct($width = null, $style = null) {
    $this->width = $width;

    if($style instanceof CellStyle) {
        $this->style = $style;
    } elseif(is_array($style)) {
        $this->style = new CellStyle();
        $this->style->setStyleByArray($style);
    } elseif($style === null) {
        $this->style = new CellStyle();
    } else {
        throw new \InvalidArgumentException("Invalid style");
    }
}

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