Skip to content

Commit

Permalink
fix coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
liborm85 committed Jan 10, 2021
1 parent 7a131d0 commit ea917c2
Show file tree
Hide file tree
Showing 29 changed files with 77 additions and 82 deletions.
26 changes: 18 additions & 8 deletions src/PhpWord/Shared/Drawing.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public static function emuToPixels($pValue = 0)
if ($pValue == 0) {
return 0;
}

return round($pValue / 9525);
}

Expand All @@ -71,9 +72,10 @@ public static function pointsToCentimeters($pValue = 0)
if ($pValue == 0) {
return 0;
}
return ((($pValue * 1.333333333) / self::DPI_96) * 2.54);

return (($pValue * 1.333333333) / self::DPI_96) * 2.54;
}

/**
* Convert points width to pixels
*
Expand All @@ -85,6 +87,7 @@ public static function pointsToPixels($pValue = 0)
if ($pValue == 0) {
return 0;
}

return $pValue * 1.333333333;
}

Expand All @@ -97,7 +100,7 @@ public static function pointsToPixels($pValue = 0)
public static function pixelsToCentimeters($pValue = 0)
{
//return $pValue * 0.028;
return (($pValue / self::DPI_96) * 2.54);
return ($pValue / self::DPI_96) * 2.54;
}

/**
Expand All @@ -111,6 +114,7 @@ public static function centimetersToPixels($pValue = 0)
if ($pValue == 0) {
return 0;
}

return ($pValue / 2.54) * self::DPI_96;
}

Expand All @@ -136,76 +140,82 @@ public static function angleToDegrees($pValue = 0)
if ($pValue == 0) {
return 0;
}

return round($pValue / 60000);
}

/**
* Convert centimeters width to twips
*
* @param integer $pValue
* @param int $pValue
* @return float
*/
public static function centimetersToTwips($pValue = 0)
{
if ($pValue == 0) {
return 0;
}

return $pValue * 566.928;
}

/**
* Convert twips width to centimeters
*
* @param integer $pValue
* @param int $pValue
* @return float
*/
public static function twipsToCentimeters($pValue = 0)
{
if ($pValue == 0) {
return 0;
}

return $pValue / 566.928;
}

/**
* Convert inches width to twips
*
* @param integer $pValue
* @param int $pValue
* @return float
*/
public static function inchesToTwips($pValue = 0)
{
if ($pValue == 0) {
return 0;
}

return $pValue * 1440;
}

/**
* Convert twips width to inches
*
* @param integer $pValue
* @param int $pValue
* @return float
*/
public static function twipsToInches($pValue = 0)
{
if ($pValue == 0) {
return 0;
}

return $pValue / 1440;
}

/**
* Convert twips width to pixels
*
* @param integer $pValue
* @param int $pValue
* @return float
*/
public static function twipsToPixels($pValue = 0)
{
if ($pValue == 0) {
return 0;
}

return round($pValue / 15.873984);
}

Expand Down
29 changes: 15 additions & 14 deletions src/PhpWord/Shared/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ private static function buildControlCharacters()
{
for ($i = 0; $i <= 19; ++$i) {
if ($i != 9 && $i != 10 && $i != 13) {
$find = '_x' . sprintf('%04s', strtoupper(dechex($i))) . '_';
$replace = chr($i);
$find = '_x' . sprintf('%04s', strtoupper(dechex($i))) . '_';
$replace = chr($i);
self::$controlCharacters[$find] = $replace;
}
}
Expand Down Expand Up @@ -69,7 +69,7 @@ public static function controlCharacterPHP2OOXML($value = '')
/**
* Return a number formatted for being integrated in xml files
* @param float $number
* @param integer $decimals
* @param int $decimals
* @return string
*/
public static function numberFormat($number, $decimals)
Expand All @@ -79,24 +79,25 @@ public static function numberFormat($number, $decimals)

/**
* @param int $dec
* @link http://stackoverflow.com/a/7153133/2235790
* @see http://stackoverflow.com/a/7153133/2235790
* @author velcrow
* @return string
*/
public static function chr($dec)
{
if ($dec<=0x7F) {
if ($dec <= 0x7F) {
return chr($dec);
}
if ($dec<=0x7FF) {
return chr(($dec>>6)+192).chr(($dec&63)+128);
if ($dec <= 0x7FF) {
return chr(($dec >> 6) + 192) . chr(($dec & 63) + 128);
}
if ($dec<=0xFFFF) {
return chr(($dec>>12)+224).chr((($dec>>6)&63)+128).chr(($dec&63)+128);
if ($dec <= 0xFFFF) {
return chr(($dec >> 12) + 224) . chr((($dec >> 6) & 63) + 128) . chr(($dec & 63) + 128);
}
if ($dec<=0x1FFFFF) {
return chr(($dec>>18)+240).chr((($dec>>12)&63)+128).chr((($dec>>6)&63)+128).chr(($dec&63)+128);
if ($dec <= 0x1FFFFF) {
return chr(($dec >> 18) + 240) . chr((($dec >> 12) & 63) + 128) . chr((($dec >> 6) & 63) + 128) . chr(($dec & 63) + 128);
}

return '';
}

Expand All @@ -119,7 +120,7 @@ public static function controlCharacterOOXML2PHP($value = '')
* Check if a string contains UTF-8 data
*
* @param string $value
* @return boolean
* @return bool
*/
public static function isUTF8($value = '')
{
Expand Down Expand Up @@ -161,7 +162,7 @@ public static function toUnicode($text)
* @param string $text UTF8 text
* @return array
* @since 0.11.0
* @link http://www.randomchaos.com/documents/?source=php_and_unicode
* @see http://www.randomchaos.com/documents/?source=php_and_unicode
*/
public static function utf8ToUnicode($text)
{
Expand Down Expand Up @@ -201,7 +202,7 @@ public static function utf8ToUnicode($text)
* @param array $unicode
* @return string
* @since 0.11.0
* @link http://www.randomchaos.com/documents/?source=php_and_unicode
* @see http://www.randomchaos.com/documents/?source=php_and_unicode
*/
private static function unicodeToEntities($unicode)
{
Expand Down
9 changes: 5 additions & 4 deletions src/PhpWord/Shared/XMLReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class XMLReader
*
* @param string $zipFile
* @param string $xmlFile
* @return \DOMDocument|false
* @throws \Exception
* @return \DOMDocument|false
*/
public function getDomFromZip($zipFile, $xmlFile)
{
Expand Down Expand Up @@ -112,8 +112,8 @@ public function getElements($path, \DOMElement $contextNode = null)
*
* @param string $prefix The prefix
* @param string $namespaceURI The URI of the namespace
* @return bool true on success or false on failure
* @throws \InvalidArgumentException If called before having loaded the DOM document
* @return bool true on success or false on failure
*/
public function registerNamespace($prefix, $namespaceURI)
{
Expand All @@ -123,6 +123,7 @@ public function registerNamespace($prefix, $namespaceURI)
if ($this->xpath === null) {
$this->xpath = new \DOMXpath($this->dom);
}

return $this->xpath->registerNamespace($prefix, $namespaceURI);
}

Expand Down Expand Up @@ -192,7 +193,7 @@ public function getValue($path, \DOMElement $contextNode = null)
*
* @param string $path
* @param \DOMElement $contextNode
* @return integer
* @return int
*/
public function countElements($path, \DOMElement $contextNode = null)
{
Expand All @@ -206,7 +207,7 @@ public function countElements($path, \DOMElement $contextNode = null)
*
* @param string $path
* @param \DOMElement $contextNode
* @return boolean
* @return bool
*/
public function elementExists($path, \DOMElement $contextNode = null)
{
Expand Down
8 changes: 3 additions & 5 deletions src/PhpWord/Shared/XMLWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function __destruct()
return;
}
if (PHP_OS != 'WINNT' && @unlink($this->tempFileName) === false) {
throw new \Exception('The file '.$this->tempFileName.' could not be deleted.');
throw new \Exception('The file ' . $this->tempFileName . ' could not be deleted.');
}
}

Expand All @@ -104,10 +104,10 @@ public function getData()
}

$this->flush();

return file_get_contents($this->tempFileName);
}


/**
* Write simple element and attribute(s) block
*
Expand All @@ -118,7 +118,6 @@ public function getData()
* @param string $element
* @param string|array $attributes
* @param string $value
* @return void
*/
public function writeElementBlock($element, $attributes, $value = null)
{
Expand All @@ -139,7 +138,6 @@ public function writeElementBlock($element, $attributes, $value = null)
* @param string $element
* @param string $attribute
* @param mixed $value
* @return void
*/
public function writeElementIf($condition, $element, $attribute = null, $value = null)
{
Expand All @@ -160,7 +158,6 @@ public function writeElementIf($condition, $element, $attribute = null, $value =
* @param bool $condition
* @param string $attribute
* @param mixed $value
* @return void
*/
public function writeAttributeIf($condition, $attribute, $value)
{
Expand All @@ -179,6 +176,7 @@ public function writeAttribute($name, $value)
if (is_float($value)) {
$value = json_encode($value);
}

return parent::writeAttribute($name, $value);
}
}
2 changes: 1 addition & 1 deletion src/PhpWord/TemplateProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

namespace PhpOffice\PhpWord;

use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Escaper\RegExp;
use PhpOffice\PhpWord\Escaper\Xml;
use PhpOffice\PhpWord\Exception\CopyFileException;
use PhpOffice\PhpWord\Exception\CreateTemporaryFileException;
use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\Shared\Text;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Shared\ZipArchive;

class TemplateProcessor
Expand Down
2 changes: 1 addition & 1 deletion src/PhpWord/Writer/ODText/Element/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

namespace PhpOffice\PhpWord\Writer\ODText\Element;

use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Element\Row as RowElement;
use PhpOffice\PhpWord\Element\Table as TableElement;
use PhpOffice\PhpWord\Shared\XMLWriter;

/**
* Table element writer
Expand Down
2 changes: 1 addition & 1 deletion src/PhpWord/Writer/ODText/Part/AbstractPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

namespace PhpOffice\PhpWord\Writer\ODText\Part;

use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Writer\Word2007\Part\AbstractPart as Word2007AbstractPart;
Expand Down
2 changes: 1 addition & 1 deletion src/PhpWord/Writer/ODText/Part/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

namespace PhpOffice\PhpWord\Writer\ODText\Part;

use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Element\AbstractContainer;
use PhpOffice\PhpWord\Element\Field;
use PhpOffice\PhpWord\Element\Image;
Expand All @@ -26,6 +25,7 @@
use PhpOffice\PhpWord\Element\TextRun;
use PhpOffice\PhpWord\Element\TrackChange;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
Expand Down
2 changes: 1 addition & 1 deletion src/PhpWord/Writer/ODText/Part/Styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

namespace PhpOffice\PhpWord\Writer\ODText\Part;

use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Shared\Converter;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/PhpWord/Writer/Word2007/Element/AbstractElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

namespace PhpOffice\PhpWord\Writer\Word2007\Element;

use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Element\AbstractElement as Element;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Shared\Text as SharedText;
use PhpOffice\PhpWord\Shared\XMLWriter;

/**
* Abstract element writer
Expand Down
Loading

0 comments on commit ea917c2

Please sign in to comment.