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

refactoring and reducing cyclomatic complexity #408

Merged
merged 3 commits into from
Oct 17, 2017
Merged
Show file tree
Hide file tree
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
5 changes: 2 additions & 3 deletions src/PhpPresentation/HashTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,12 @@ public function add(ComparableInterface $pSource)
{
// Determine hashcode
$hashIndex = $pSource->getHashIndex();

$hashCode = $pSource->getHashCode();

if (is_null($hashIndex)) {
$hashCode = $pSource->getHashCode();
} elseif (isset($this->keyMap[$hashIndex])) {
$hashCode = $this->keyMap[$hashIndex];
} else {
$hashCode = $pSource->getHashCode();
}

// Add value
Expand Down
9 changes: 3 additions & 6 deletions src/PhpPresentation/PhpPresentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,8 @@ public function removeSlideByIndex($index = 0)
{
if ($index > count($this->slideCollection) - 1) {
throw new \Exception("Slide index is out of bounds.");
} else {
array_splice($this->slideCollection, $index, 1);
}
array_splice($this->slideCollection, $index, 1);

return $this;
}
Expand All @@ -241,9 +240,8 @@ public function getSlide($index = 0)
{
if ($index > count($this->slideCollection) - 1) {
throw new \Exception("Slide index is out of bounds.");
} else {
return $this->slideCollection[$index];
}
return $this->slideCollection[$index];
}

/**
Expand Down Expand Up @@ -306,9 +304,8 @@ public function setActiveSlideIndex($index = 0)
{
if ($index > count($this->slideCollection) - 1) {
throw new \Exception("Active slide index is out of bounds.");
} else {
$this->activeSlideIndex = $index;
}
$this->activeSlideIndex = $index;

return $this->getActiveSlide();
}
Expand Down
6 changes: 2 additions & 4 deletions src/PhpPresentation/Shape/RichText/Paragraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,10 @@ public function getRichTextElements()
*/
public function setRichTextElements($pElements = null)
{
if (is_array($pElements)) {
$this->richTextElements = $pElements;
} else {
if (!is_array($pElements)) {
throw new \Exception("Invalid \PhpOffice\PhpPresentation\Shape\RichText\TextElementInterface[] array passed.");
}

$this->richTextElements = $pElements;
return $this;
}

Expand Down
17 changes: 6 additions & 11 deletions src/PhpPresentation/Shape/Table/Cell.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,18 @@ public function getParagraph($index = 0)
public function createParagraph()
{
$this->richTextParagraphs[] = new Paragraph();
$totalRichTextParagraphs = count($this->richTextParagraphs);
$this->activeParagraph = $totalRichTextParagraphs - 1;

if (count($this->richTextParagraphs) > 1) {
if ($totalRichTextParagraphs > 1) {
$alignment = clone $this->getActiveParagraph()->getAlignment();
$font = clone $this->getActiveParagraph()->getFont();
$bulletStyle = clone $this->getActiveParagraph()->getBulletStyle();

$this->activeParagraph = count($this->richTextParagraphs) - 1;

$this->getActiveParagraph()->setAlignment($alignment);
$this->getActiveParagraph()->setFont($font);
$this->getActiveParagraph()->setBulletStyle($bulletStyle);
} else {
$this->activeParagraph = count($this->richTextParagraphs) - 1;
}

return $this->getActiveParagraph();
}

Expand Down Expand Up @@ -279,13 +276,11 @@ public function getParagraphs()
*/
public function setParagraphs($paragraphs = null)
{
if (is_array($paragraphs)) {
$this->richTextParagraphs = $paragraphs;
$this->activeParagraph = count($this->richTextParagraphs) - 1;
} else {
if (!is_array($paragraphs)) {
throw new \Exception("Invalid \PhpOffice\PhpPresentation\Shape\RichText\Paragraph[] array passed.");
}

$this->richTextParagraphs = $paragraphs;
$this->activeParagraph = count($this->richTextParagraphs) - 1;
return $this;
}

Expand Down
4 changes: 1 addition & 3 deletions src/PhpPresentation/Shape/Table/Row.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,9 @@ public function nextCell()
$this->activeCellIndex++;
if (isset($this->cells[$this->activeCellIndex])) {
$this->cells[$this->activeCellIndex]->setFill(clone $this->getFill());

return $this->cells[$this->activeCellIndex];
} else {
throw new \Exception("Cell count out of bounds.");
}
throw new \Exception("Cell count out of bounds.");
}

/**
Expand Down
4 changes: 0 additions & 4 deletions src/PhpPresentation/Writer/ODPresentation/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,6 @@ public function writeShapeTxt(XMLWriter $objWriter, RichText $shape)
$objWriter->startElement('text:line-break');
$objWriter->endElement();
$objWriter->endElement();
} else {
//echo '<pre>'.print_r($richtext, true).'</pre>';
}
}
$objWriter->endElement();
Expand Down Expand Up @@ -549,8 +547,6 @@ public function writeShapeTxt(XMLWriter $objWriter, RichText $shape)
$objWriter->startElement('text:line-break');
$objWriter->endElement();
$objWriter->endElement();
} else {
//echo '<pre>'.print_r($richtext, true).'</pre>';
}
}
$objWriter->endElement();
Expand Down