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

Make styles to work as a instance property of PhpWord #2763

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/PhpWord/Element/ListItem.php
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@

namespace PhpOffice\PhpWord\Element;

use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\Text as SharedText;
use PhpOffice\PhpWord\Style\ListItem as ListItemStyle;

@@ -69,6 +70,15 @@ public function __construct($text, $depth = 0, $fontStyle = null, $listStyle = n
}
}

/**
* Set PhpWord as reference.
*/
public function setPhpWord(?PhpWord $phpWord = null): void
{
parent::setPhpWord($phpWord);
$this->style->setPhpWord($phpWord);
}

/**
* Get style.
*
10 changes: 10 additions & 0 deletions src/PhpWord/Element/ListItemRun.php
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@

namespace PhpOffice\PhpWord\Element;

use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Style\ListItem as ListItemStyle;

/**
@@ -64,6 +65,15 @@ public function __construct($depth = 0, $listStyle = null, $paragraphStyle = nul
parent::__construct($paragraphStyle);
}

/**
* Set PhpWord as reference.
*/
public function setPhpWord(?PhpWord $phpWord = null): void
{
parent::setPhpWord($phpWord);
$this->style->setPhpWord($phpWord);
}

/**
* Get ListItem style.
*
25 changes: 21 additions & 4 deletions src/PhpWord/Element/Title.php
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
namespace PhpOffice\PhpWord\Element;

use InvalidArgumentException;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\Text as SharedText;
use PhpOffice\PhpWord\Style;

@@ -79,16 +80,32 @@
}

$this->depth = $depth;
$styleName = $depth === 0 ? 'Title' : "Heading_{$this->depth}";
if (array_key_exists($styleName, Style::getStyles())) {
$this->style = str_replace('_', '', $styleName);
}
$this->setStyleByDepth(Style::getStyles());

if ($pageNumber !== null) {
$this->pageNumber = $pageNumber;
}
}

private function setStyleByDepth($styles)

Check failure on line 90 in src/PhpWord/Element/Title.php

GitHub Actions / PHP Static Analysis (8.1)

Method PhpOffice\PhpWord\Element\Title::setStyleByDepth() has parameter $styles with no type specified.

Check failure on line 90 in src/PhpWord/Element/Title.php

GitHub Actions / PHP Static Analysis (8.1)

Method PhpOffice\PhpWord\Element\Title::setStyleByDepth() has no return type specified.

Check failure on line 90 in src/PhpWord/Element/Title.php

GitHub Actions / PHP Static Analysis (8.2)

Method PhpOffice\PhpWord\Element\Title::setStyleByDepth() has parameter $styles with no type specified.

Check failure on line 90 in src/PhpWord/Element/Title.php

GitHub Actions / PHP Static Analysis (8.2)

Method PhpOffice\PhpWord\Element\Title::setStyleByDepth() has no return type specified.

Check failure on line 90 in src/PhpWord/Element/Title.php

GitHub Actions / PHP Static Analysis (8.4)

Method PhpOffice\PhpWord\Element\Title::setStyleByDepth() has parameter $styles with no type specified.

Check failure on line 90 in src/PhpWord/Element/Title.php

GitHub Actions / PHP Static Analysis (8.4)

Method PhpOffice\PhpWord\Element\Title::setStyleByDepth() has no return type specified.

Check failure on line 90 in src/PhpWord/Element/Title.php

GitHub Actions / PHP Static Analysis (8.3)

Method PhpOffice\PhpWord\Element\Title::setStyleByDepth() has parameter $styles with no type specified.

Check failure on line 90 in src/PhpWord/Element/Title.php

GitHub Actions / PHP Static Analysis (8.3)

Method PhpOffice\PhpWord\Element\Title::setStyleByDepth() has no return type specified.

Check failure on line 90 in src/PhpWord/Element/Title.php

GitHub Actions / PHP Static Analysis (7.4)

Method PhpOffice\PhpWord\Element\Title::setStyleByDepth() has parameter $styles with no type specified.

Check failure on line 90 in src/PhpWord/Element/Title.php

GitHub Actions / PHP Static Analysis (7.4)

Method PhpOffice\PhpWord\Element\Title::setStyleByDepth() has no return type specified.

Check failure on line 90 in src/PhpWord/Element/Title.php

GitHub Actions / PHP Static Analysis (7.3)

Method PhpOffice\PhpWord\Element\Title::setStyleByDepth() has parameter $styles with no type specified.

Check failure on line 90 in src/PhpWord/Element/Title.php

GitHub Actions / PHP Static Analysis (7.3)

Method PhpOffice\PhpWord\Element\Title::setStyleByDepth() has no return type specified.

Check failure on line 90 in src/PhpWord/Element/Title.php

GitHub Actions / PHP Static Analysis (7.2)

Method PhpOffice\PhpWord\Element\Title::setStyleByDepth() has parameter $styles with no type specified.

Check failure on line 90 in src/PhpWord/Element/Title.php

GitHub Actions / PHP Static Analysis (7.2)

Method PhpOffice\PhpWord\Element\Title::setStyleByDepth() has no return type specified.

Check failure on line 90 in src/PhpWord/Element/Title.php

GitHub Actions / PHP Static Analysis (8.0)

Method PhpOffice\PhpWord\Element\Title::setStyleByDepth() has parameter $styles with no type specified.

Check failure on line 90 in src/PhpWord/Element/Title.php

GitHub Actions / PHP Static Analysis (8.0)

Method PhpOffice\PhpWord\Element\Title::setStyleByDepth() has no return type specified.

Check failure on line 90 in src/PhpWord/Element/Title.php

GitHub Actions / PHP Static Analysis (8.3)

Method PhpOffice\PhpWord\Element\Title::setStyleByDepth() has parameter $styles with no type specified.

Check failure on line 90 in src/PhpWord/Element/Title.php

GitHub Actions / PHP Static Analysis (8.3)

Method PhpOffice\PhpWord\Element\Title::setStyleByDepth() has no return type specified.

Check failure on line 90 in src/PhpWord/Element/Title.php

GitHub Actions / PHP Static Analysis (8.4)

Method PhpOffice\PhpWord\Element\Title::setStyleByDepth() has parameter $styles with no type specified.

Check failure on line 90 in src/PhpWord/Element/Title.php

GitHub Actions / PHP Static Analysis (8.4)

Method PhpOffice\PhpWord\Element\Title::setStyleByDepth() has no return type specified.

Check failure on line 90 in src/PhpWord/Element/Title.php

GitHub Actions / PHP Static Analysis (8.0)

Method PhpOffice\PhpWord\Element\Title::setStyleByDepth() has parameter $styles with no type specified.

Check failure on line 90 in src/PhpWord/Element/Title.php

GitHub Actions / PHP Static Analysis (8.0)

Method PhpOffice\PhpWord\Element\Title::setStyleByDepth() has no return type specified.

Check failure on line 90 in src/PhpWord/Element/Title.php

GitHub Actions / PHP Static Analysis (8.2)

Method PhpOffice\PhpWord\Element\Title::setStyleByDepth() has parameter $styles with no type specified.

Check failure on line 90 in src/PhpWord/Element/Title.php

GitHub Actions / PHP Static Analysis (8.2)

Method PhpOffice\PhpWord\Element\Title::setStyleByDepth() has no return type specified.

Check failure on line 90 in src/PhpWord/Element/Title.php

GitHub Actions / PHP Static Analysis (7.4)

Method PhpOffice\PhpWord\Element\Title::setStyleByDepth() has parameter $styles with no type specified.

Check failure on line 90 in src/PhpWord/Element/Title.php

GitHub Actions / PHP Static Analysis (7.4)

Method PhpOffice\PhpWord\Element\Title::setStyleByDepth() has no return type specified.

Check failure on line 90 in src/PhpWord/Element/Title.php

GitHub Actions / PHP Static Analysis (7.3)

Method PhpOffice\PhpWord\Element\Title::setStyleByDepth() has parameter $styles with no type specified.

Check failure on line 90 in src/PhpWord/Element/Title.php

GitHub Actions / PHP Static Analysis (7.3)

Method PhpOffice\PhpWord\Element\Title::setStyleByDepth() has no return type specified.

Check failure on line 90 in src/PhpWord/Element/Title.php

GitHub Actions / PHP Static Analysis (8.1)

Method PhpOffice\PhpWord\Element\Title::setStyleByDepth() has parameter $styles with no type specified.

Check failure on line 90 in src/PhpWord/Element/Title.php

GitHub Actions / PHP Static Analysis (8.1)

Method PhpOffice\PhpWord\Element\Title::setStyleByDepth() has no return type specified.

Check failure on line 90 in src/PhpWord/Element/Title.php

GitHub Actions / PHP Static Analysis (7.2)

Method PhpOffice\PhpWord\Element\Title::setStyleByDepth() has parameter $styles with no type specified.

Check failure on line 90 in src/PhpWord/Element/Title.php

GitHub Actions / PHP Static Analysis (7.2)

Method PhpOffice\PhpWord\Element\Title::setStyleByDepth() has no return type specified.
{
$styleName = $this->depth === 0 ? 'Title' : "Heading_{$this->depth}";
if (array_key_exists($styleName, $styles)) {
$this->style = str_replace('_', '', $styleName);
}
}

/**
* Set PhpWord as reference.
*/
public function setPhpWord(?PhpWord $phpWord = null): void
{
parent::setPhpWord($phpWord);
if ($phpWord instanceof PhpWord) {
$this->setStyleByDepth($phpWord->getStyles());
}
}

/**
* Get Title Text content.
*
196 changes: 172 additions & 24 deletions src/PhpWord/PhpWord.php
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@
use BadMethodCallException;
use PhpOffice\PhpWord\Element\Section;
use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\Style\AbstractStyle;

/**
* PHPWord main class.
@@ -67,6 +68,13 @@
* @since 0.12.0
*/
private $metadata = [];

/**
* Style register.
*
* @var array
*/
private $styles = [];

/**
* Create new instance.
@@ -77,7 +85,6 @@
{
// Reset Media and styles
Media::resetElements();
Style::resetStyles();
Settings::setDefaultRtl(null);

// Collection
@@ -111,19 +118,13 @@

$getCollection = [];
$addCollection = [];
$addStyle = [];

$collections = ['Bookmark', 'Title', 'Footnote', 'Endnote', 'Chart', 'Comment'];
foreach ($collections as $collection) {
$getCollection[] = strtolower("get{$collection}s");
$addCollection[] = strtolower("add{$collection}");
}

$styles = ['Paragraph', 'Font', 'Table', 'Numbering', 'Link', 'Title'];
foreach ($styles as $style) {
$addStyle[] = strtolower("add{$style}Style");
}

// Run get collection method
if (in_array($function, $getCollection)) {
$key = ucfirst(str_replace('get', '', $function));
@@ -140,11 +141,6 @@
return $collectionObject->addItem($args[0] ?? null);
}

// Run add style method
if (in_array($function, $addStyle)) {
return forward_static_call_array(['PhpOffice\\PhpWord\\Style', $function], $args);
}

// Exception
throw new BadMethodCallException("Method $function is not defined.");
}
@@ -311,18 +307,6 @@
Settings::setDefaultFontSize($fontSize);
}

/**
* Set default paragraph style definition to styles.xml.
*
* @param array $styles Paragraph style definition
*
* @return Style\Paragraph
*/
public function setDefaultParagraphStyle($styles)
{
return Style::setDefaultParagraphStyle($styles);
}

/**
* Save to file or download.
*
@@ -408,4 +392,168 @@

return $this;
}

/**
* Add paragraph style.
*
* @param string $styleName
* @param AbstractStyle|array $styles
*
* @return \PhpOffice\PhpWord\Style\Paragraph
*/
public function addParagraphStyle($styleName, $styles)
{
return $this->setStyleValues($styleName, new Style\Paragraph(), $styles);

Check failure on line 406 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.1)

Method PhpOffice\PhpWord\PhpWord::addParagraphStyle() should return PhpOffice\PhpWord\Style\Paragraph but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 406 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.2)

Method PhpOffice\PhpWord\PhpWord::addParagraphStyle() should return PhpOffice\PhpWord\Style\Paragraph but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 406 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.4)

Method PhpOffice\PhpWord\PhpWord::addParagraphStyle() should return PhpOffice\PhpWord\Style\Paragraph but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 406 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.3)

Method PhpOffice\PhpWord\PhpWord::addParagraphStyle() should return PhpOffice\PhpWord\Style\Paragraph but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 406 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.4)

Method PhpOffice\PhpWord\PhpWord::addParagraphStyle() should return PhpOffice\PhpWord\Style\Paragraph but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 406 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.3)

Method PhpOffice\PhpWord\PhpWord::addParagraphStyle() should return PhpOffice\PhpWord\Style\Paragraph but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 406 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.2)

Method PhpOffice\PhpWord\PhpWord::addParagraphStyle() should return PhpOffice\PhpWord\Style\Paragraph but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 406 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.0)

Method PhpOffice\PhpWord\PhpWord::addParagraphStyle() should return PhpOffice\PhpWord\Style\Paragraph but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 406 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.3)

Method PhpOffice\PhpWord\PhpWord::addParagraphStyle() should return PhpOffice\PhpWord\Style\Paragraph but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 406 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.4)

Method PhpOffice\PhpWord\PhpWord::addParagraphStyle() should return PhpOffice\PhpWord\Style\Paragraph but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 406 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.0)

Method PhpOffice\PhpWord\PhpWord::addParagraphStyle() should return PhpOffice\PhpWord\Style\Paragraph but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 406 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.2)

Method PhpOffice\PhpWord\PhpWord::addParagraphStyle() should return PhpOffice\PhpWord\Style\Paragraph but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 406 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.4)

Method PhpOffice\PhpWord\PhpWord::addParagraphStyle() should return PhpOffice\PhpWord\Style\Paragraph but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 406 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.3)

Method PhpOffice\PhpWord\PhpWord::addParagraphStyle() should return PhpOffice\PhpWord\Style\Paragraph but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 406 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.1)

Method PhpOffice\PhpWord\PhpWord::addParagraphStyle() should return PhpOffice\PhpWord\Style\Paragraph but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 406 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.2)

Method PhpOffice\PhpWord\PhpWord::addParagraphStyle() should return PhpOffice\PhpWord\Style\Paragraph but returns PhpOffice\PhpWord\Style\AbstractStyle.
}

/**
* Add font style.
*
* @param string $styleName
* @param AbstractStyle|array $fontStyle
* @param AbstractStyle|array $paragraphStyle
*
* @return \PhpOffice\PhpWord\Style\Font
*/
public function addFontStyle($styleName, $fontStyle, $paragraphStyle = null)
{
return $this->setStyleValues($styleName, new Style\Font('text', $paragraphStyle), $fontStyle);

Check failure on line 420 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.1)

Method PhpOffice\PhpWord\PhpWord::addFontStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 420 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.2)

Method PhpOffice\PhpWord\PhpWord::addFontStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 420 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.4)

Method PhpOffice\PhpWord\PhpWord::addFontStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 420 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.3)

Method PhpOffice\PhpWord\PhpWord::addFontStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 420 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.4)

Method PhpOffice\PhpWord\PhpWord::addFontStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 420 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.3)

Method PhpOffice\PhpWord\PhpWord::addFontStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 420 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.2)

Method PhpOffice\PhpWord\PhpWord::addFontStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 420 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.0)

Method PhpOffice\PhpWord\PhpWord::addFontStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 420 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.3)

Method PhpOffice\PhpWord\PhpWord::addFontStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 420 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.4)

Method PhpOffice\PhpWord\PhpWord::addFontStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 420 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.0)

Method PhpOffice\PhpWord\PhpWord::addFontStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 420 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.2)

Method PhpOffice\PhpWord\PhpWord::addFontStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 420 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.4)

Method PhpOffice\PhpWord\PhpWord::addFontStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 420 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.3)

Method PhpOffice\PhpWord\PhpWord::addFontStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 420 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.1)

Method PhpOffice\PhpWord\PhpWord::addFontStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 420 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.2)

Method PhpOffice\PhpWord\PhpWord::addFontStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.
}

/**
* Add link style.
*
* @param string $styleName
* @param AbstractStyle|array $styles
*
* @return \PhpOffice\PhpWord\Style\Font
*/
public function addLinkStyle($styleName, $styles)
{
return $this->setStyleValues($styleName, new Style\Font('link'), $styles);

Check failure on line 433 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.1)

Method PhpOffice\PhpWord\PhpWord::addLinkStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 433 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.2)

Method PhpOffice\PhpWord\PhpWord::addLinkStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 433 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.4)

Method PhpOffice\PhpWord\PhpWord::addLinkStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 433 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.3)

Method PhpOffice\PhpWord\PhpWord::addLinkStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 433 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.4)

Method PhpOffice\PhpWord\PhpWord::addLinkStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 433 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.3)

Method PhpOffice\PhpWord\PhpWord::addLinkStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 433 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.2)

Method PhpOffice\PhpWord\PhpWord::addLinkStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 433 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.0)

Method PhpOffice\PhpWord\PhpWord::addLinkStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 433 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.3)

Method PhpOffice\PhpWord\PhpWord::addLinkStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 433 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.4)

Method PhpOffice\PhpWord\PhpWord::addLinkStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 433 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.0)

Method PhpOffice\PhpWord\PhpWord::addLinkStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 433 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.2)

Method PhpOffice\PhpWord\PhpWord::addLinkStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 433 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.4)

Method PhpOffice\PhpWord\PhpWord::addLinkStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 433 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.3)

Method PhpOffice\PhpWord\PhpWord::addLinkStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 433 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.1)

Method PhpOffice\PhpWord\PhpWord::addLinkStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 433 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.2)

Method PhpOffice\PhpWord\PhpWord::addLinkStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.
}

/**
* Add numbering style.
*
* @param string $styleName
* @param AbstractStyle|array $styleValues
*
* @return \PhpOffice\PhpWord\Style\Numbering
*
* @since 0.10.0
*/
public function addNumberingStyle($styleName, $styleValues)
{
return $this->setStyleValues($styleName, new Style\Numbering(), $styleValues);

Check failure on line 448 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.1)

Method PhpOffice\PhpWord\PhpWord::addNumberingStyle() should return PhpOffice\PhpWord\Style\Numbering but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 448 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.2)

Method PhpOffice\PhpWord\PhpWord::addNumberingStyle() should return PhpOffice\PhpWord\Style\Numbering but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 448 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.4)

Method PhpOffice\PhpWord\PhpWord::addNumberingStyle() should return PhpOffice\PhpWord\Style\Numbering but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 448 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.3)

Method PhpOffice\PhpWord\PhpWord::addNumberingStyle() should return PhpOffice\PhpWord\Style\Numbering but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 448 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.4)

Method PhpOffice\PhpWord\PhpWord::addNumberingStyle() should return PhpOffice\PhpWord\Style\Numbering but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 448 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.3)

Method PhpOffice\PhpWord\PhpWord::addNumberingStyle() should return PhpOffice\PhpWord\Style\Numbering but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 448 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.2)

Method PhpOffice\PhpWord\PhpWord::addNumberingStyle() should return PhpOffice\PhpWord\Style\Numbering but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 448 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.0)

Method PhpOffice\PhpWord\PhpWord::addNumberingStyle() should return PhpOffice\PhpWord\Style\Numbering but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 448 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.3)

Method PhpOffice\PhpWord\PhpWord::addNumberingStyle() should return PhpOffice\PhpWord\Style\Numbering but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 448 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.4)

Method PhpOffice\PhpWord\PhpWord::addNumberingStyle() should return PhpOffice\PhpWord\Style\Numbering but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 448 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.0)

Method PhpOffice\PhpWord\PhpWord::addNumberingStyle() should return PhpOffice\PhpWord\Style\Numbering but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 448 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.2)

Method PhpOffice\PhpWord\PhpWord::addNumberingStyle() should return PhpOffice\PhpWord\Style\Numbering but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 448 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.4)

Method PhpOffice\PhpWord\PhpWord::addNumberingStyle() should return PhpOffice\PhpWord\Style\Numbering but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 448 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.3)

Method PhpOffice\PhpWord\PhpWord::addNumberingStyle() should return PhpOffice\PhpWord\Style\Numbering but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 448 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.1)

Method PhpOffice\PhpWord\PhpWord::addNumberingStyle() should return PhpOffice\PhpWord\Style\Numbering but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 448 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.2)

Method PhpOffice\PhpWord\PhpWord::addNumberingStyle() should return PhpOffice\PhpWord\Style\Numbering but returns PhpOffice\PhpWord\Style\AbstractStyle.
}

/**
* Add title style.
*
* @param null|int $depth Provide null to set title font
* @param AbstractStyle|array $fontStyle
* @param AbstractStyle|array $paragraphStyle
*
* @return \PhpOffice\PhpWord\Style\Font
*/
public function addTitleStyle($depth, $fontStyle, $paragraphStyle = null)
{
if (empty($depth)) {
$styleName = 'Title';
} else {
$styleName = "Heading_{$depth}";
}

return $this->setStyleValues($styleName, new Style\Font('title', $paragraphStyle), $fontStyle);

Check failure on line 468 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.1)

Method PhpOffice\PhpWord\PhpWord::addTitleStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 468 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.2)

Method PhpOffice\PhpWord\PhpWord::addTitleStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 468 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.4)

Method PhpOffice\PhpWord\PhpWord::addTitleStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 468 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.3)

Method PhpOffice\PhpWord\PhpWord::addTitleStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 468 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.4)

Method PhpOffice\PhpWord\PhpWord::addTitleStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 468 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.3)

Method PhpOffice\PhpWord\PhpWord::addTitleStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 468 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.2)

Method PhpOffice\PhpWord\PhpWord::addTitleStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 468 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.0)

Method PhpOffice\PhpWord\PhpWord::addTitleStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 468 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.3)

Method PhpOffice\PhpWord\PhpWord::addTitleStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 468 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.4)

Method PhpOffice\PhpWord\PhpWord::addTitleStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 468 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.0)

Method PhpOffice\PhpWord\PhpWord::addTitleStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 468 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.2)

Method PhpOffice\PhpWord\PhpWord::addTitleStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 468 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.4)

Method PhpOffice\PhpWord\PhpWord::addTitleStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 468 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.3)

Method PhpOffice\PhpWord\PhpWord::addTitleStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 468 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.1)

Method PhpOffice\PhpWord\PhpWord::addTitleStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 468 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.2)

Method PhpOffice\PhpWord\PhpWord::addTitleStyle() should return PhpOffice\PhpWord\Style\Font but returns PhpOffice\PhpWord\Style\AbstractStyle.
}

/**
* Add table style.
*
* @param string $styleName
* @param array $styleTable
* @param null|array $styleFirstRow
*
* @return \PhpOffice\PhpWord\Style\Table
*/
public function addTableStyle($styleName, $styleTable, $styleFirstRow = null)
{
return $this->setStyleValues($styleName, new Style\Table($styleTable, $styleFirstRow), null);

Check failure on line 482 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.1)

Method PhpOffice\PhpWord\PhpWord::addTableStyle() should return PhpOffice\PhpWord\Style\Table but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 482 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.2)

Method PhpOffice\PhpWord\PhpWord::addTableStyle() should return PhpOffice\PhpWord\Style\Table but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 482 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.4)

Method PhpOffice\PhpWord\PhpWord::addTableStyle() should return PhpOffice\PhpWord\Style\Table but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 482 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.3)

Method PhpOffice\PhpWord\PhpWord::addTableStyle() should return PhpOffice\PhpWord\Style\Table but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 482 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.4)

Method PhpOffice\PhpWord\PhpWord::addTableStyle() should return PhpOffice\PhpWord\Style\Table but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 482 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.3)

Method PhpOffice\PhpWord\PhpWord::addTableStyle() should return PhpOffice\PhpWord\Style\Table but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 482 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.2)

Method PhpOffice\PhpWord\PhpWord::addTableStyle() should return PhpOffice\PhpWord\Style\Table but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 482 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.0)

Method PhpOffice\PhpWord\PhpWord::addTableStyle() should return PhpOffice\PhpWord\Style\Table but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 482 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.3)

Method PhpOffice\PhpWord\PhpWord::addTableStyle() should return PhpOffice\PhpWord\Style\Table but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 482 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.4)

Method PhpOffice\PhpWord\PhpWord::addTableStyle() should return PhpOffice\PhpWord\Style\Table but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 482 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.0)

Method PhpOffice\PhpWord\PhpWord::addTableStyle() should return PhpOffice\PhpWord\Style\Table but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 482 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.2)

Method PhpOffice\PhpWord\PhpWord::addTableStyle() should return PhpOffice\PhpWord\Style\Table but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 482 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.4)

Method PhpOffice\PhpWord\PhpWord::addTableStyle() should return PhpOffice\PhpWord\Style\Table but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 482 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.3)

Method PhpOffice\PhpWord\PhpWord::addTableStyle() should return PhpOffice\PhpWord\Style\Table but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 482 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (8.1)

Method PhpOffice\PhpWord\PhpWord::addTableStyle() should return PhpOffice\PhpWord\Style\Table but returns PhpOffice\PhpWord\Style\AbstractStyle.

Check failure on line 482 in src/PhpWord/PhpWord.php

GitHub Actions / PHP Static Analysis (7.2)

Method PhpOffice\PhpWord\PhpWord::addTableStyle() should return PhpOffice\PhpWord\Style\Table but returns PhpOffice\PhpWord\Style\AbstractStyle.
}

/**
* Set default paragraph style.
*
* @param AbstractStyle|array $styles Paragraph style definition
*
* @return \PhpOffice\PhpWord\Style\Paragraph
*/
public function setDefaultParagraphStyle($styles)
{
return $this->addParagraphStyle('Normal', $styles);
}

/**
* Get all styles.
*
* @return AbstractStyle[]
*/
public function getStyles()
{
$styles = Style::getStyles();
$index = Style::countStyles() + 1;
foreach ($this->styles AS $name => $style) {
if (isset($styles[$name])) {
$style->setIndex($styles[$name]->getIndex());
} else {
$style->setIndex($index);
$index ++;
}
$styles[$name] = $style;
}
return $styles;
}

/**
* Get style by name.
*
* @param string $styleName
*
* @return ?AbstractStyle Paragraph|Font|Table|Numbering
*/
public function getStyle($styleName)
{
return $this->styles[$styleName] ?? Style::getStyle($styleName);
}

/**
* Set style values and put it to style collection.
*
* The $styleValues could be an array or object
*
* @param string $name
* @param AbstractStyle $style
* @param AbstractStyle|array $value
*
* @return AbstractStyle
*/
private function setStyleValues($name, $style, $value = null)
{
if (!isset($this->styles[$name])) {
if ($value !== null) {
if (is_array($value)) {
$style->setStyleByArray($value);
} elseif ($value instanceof AbstractStyle) {
if (get_class($style) == get_class($value)) {
$style = $value;
}
}
}
$style->setStyleName($name);
$this->styles[$name] = $style;
}

return $this->styles[$name];
}
}
Loading