Skip to content
This repository has been archived by the owner on Apr 6, 2018. It is now read-only.

Commit

Permalink
Formal and codestyle-related changes
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueM committed Dec 9, 2012
1 parent d98c237 commit 48b9221
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 147 deletions.
2 changes: 0 additions & 2 deletions autoload.php
Expand Up @@ -15,5 +15,3 @@ function ($className) {
require __DIR__."/lib/$filename";
}
);


9 changes: 3 additions & 6 deletions lib/TEIShredder/Element.php
Expand Up @@ -26,12 +26,11 @@

namespace TEIShredder;

use \LogicException;
use LogicException;

/**
* Model class for any XML element in the underlying TEI document that is
* addressable (i.e.: that has an
* @xml:id attribute).
* addressable (i.e.: that has an @xml:id attribute).
* @package TEIShredder
* @author Carsten Bluem <carsten@bluem.net>
* @copyright 2012 Carsten Bluem <carsten@bluem.net>
Expand Down Expand Up @@ -62,7 +61,6 @@ class Element extends Model
* Page number
*
* @var string
* @todo Redundant: element is assigned to a section, and sections know their page
*/
protected $page;

Expand All @@ -84,13 +82,12 @@ public function persistableData()
{
// Basic integrity check
foreach (array('xmlid', 'element', 'page', 'chunk') as $property) {
if (is_null($this->$property) or
if (is_null($this->$property) ||
'' === $this->$property
) {
throw new LogicException("Integrity check failed: $property cannot be empty.");
}
}
return $this->toArray();
}

}
7 changes: 3 additions & 4 deletions lib/TEIShredder/ElementGateway.php
Expand Up @@ -26,8 +26,8 @@

namespace TEIShredder;

use \InvalidArgumentException;
use \PDO;
use InvalidArgumentException;
use PDO;

/**
* Gateway for Element objects
Expand All @@ -42,7 +42,7 @@ class ElementGateway extends AbstractGateway
{

/**
* {@inheritdoc}
* {@inheritDoc}
*/
protected function tableName()
{
Expand Down Expand Up @@ -89,5 +89,4 @@ public function find()
$properties = array_keys($element->toArray());
return parent::performFind(get_class($element), $properties, 'chunk', func_get_args());
}

}
3 changes: 1 addition & 2 deletions lib/TEIShredder/Model.php
Expand Up @@ -26,7 +26,7 @@

namespace TEIShredder;

use \UnexpectedValueException;
use UnexpectedValueException;

/**
* Simple base class for TEIShredder model classes.
Expand Down Expand Up @@ -116,5 +116,4 @@ public function toArray()
}
return $array;
}

}
18 changes: 7 additions & 11 deletions lib/TEIShredder/NamedEntity.php
Expand Up @@ -26,7 +26,7 @@

namespace TEIShredder;

use \LogicException;
use LogicException;

/**
* Model class for named entities in the underlying TEI document.
Expand All @@ -50,7 +50,7 @@ class NamedEntity extends Model
{

/**
* @xml:id value
* Enclosing tag's @xml:id value
* @var int
*/
protected $xmlid;
Expand All @@ -59,7 +59,6 @@ class NamedEntity extends Model
* Page number
*
* @var string
* @todo Redundant: element is assigned to a section, and sections knows their page
*/
protected $page;

Expand All @@ -71,9 +70,8 @@ class NamedEntity extends Model
protected $domain;

/**
* Value of element's
* @key attribute in underlying document. Usually some kind
* of identifier (database record) or Semantic Web URI.
* Value of element's @key attribute in underlying document. Usually some
* kind of identifier (database record) or Semantic Web URI.
* @var string
*/
protected $identifier;
Expand Down Expand Up @@ -122,10 +120,9 @@ class NamedEntity extends Model
*/
public function persistableData()
{

// Basic integrity check
foreach (array('page', 'domain', 'identifier', 'notation') as $property) {
if (is_null($this->$property) or
if (is_null($this->$property) ||
'' === $this->$property
) {
$msg = sprintf(
Expand Down Expand Up @@ -165,7 +162,7 @@ public function __set($name, $value)
}

if ('contextstart' == $name) {
if (mb_strlen($this->contextstart) >= $length and
if (mb_strlen($this->contextstart) >= $length &&
false !== $pos = strrpos($this->contextstart, ' ', -$length)
) {
// Limit length of the context start
Expand All @@ -175,13 +172,12 @@ public function __set($name, $value)
}

if ('contextend' == $name) {
if (mb_strlen($this->contextend) >= $length and
if (mb_strlen($this->contextend) >= $length &&
false !== $pos = strpos($this->contextend, ' ', $length)
) {
// Limit length of the context end
$this->contextend = substr($this->contextend, 0, $pos).$omission;
}
}
}

}
6 changes: 2 additions & 4 deletions lib/TEIShredder/NamedEntityGateway.php
Expand Up @@ -26,8 +26,7 @@

namespace TEIShredder;

use \InvalidArgumentException;
use \PDO;
use PDO;

/**
* Gateway for volume objects
Expand All @@ -42,7 +41,7 @@ class NamedEntityGateway extends AbstractGateway
{

/**
* {@inheritdoc}
* {@inheritDoc}
*/
protected function tableName()
{
Expand Down Expand Up @@ -103,5 +102,4 @@ public function findDistinctNotations($domain, $identifier)
ksort($notations);
return array_values($notations);
}

}
17 changes: 5 additions & 12 deletions lib/TEIShredder/Page.php
Expand Up @@ -26,7 +26,7 @@

namespace TEIShredder;

use \LogicException;
use LogicException;

/**
* Model class for physical pages in the underlying TEI document.
Expand All @@ -48,29 +48,25 @@ class Page extends Model

/**
* Page number. (Numerical unique number, not the "label"
* that might have been encoded into
* @n)
* that might have been encoded into @n)
* @var int
*/
protected $number;

/**
* Value of <pb />'s
* @xml:id attribute value
* Value of <pb />'s @xml:id attribute value
* @var string
*/
protected $xmlid;

/**
* Value of <pb />'s
* @n attribute value
* Value of <pb />'s @n attribute value
* @var string
*/
protected $n;

/**
* Value of <pb />'s
* @rend attribute value
* Value of <pb />'s @rend attribute value
* @var int
*/
protected $rend;
Expand All @@ -86,7 +82,6 @@ class Page extends Model
* Plaintext
*
* @var int
* @todo Redundancy: Chunks also contain the plaintext.
*/
protected $plaintext;

Expand All @@ -99,7 +94,6 @@ class Page extends Model
*/
public function persistableData()
{

// Basic integrity check
foreach (array('number', 'volume') as $property) {
if (0 >= intval($this->$property)) {
Expand All @@ -109,5 +103,4 @@ public function persistableData()

return $this->toArray();
}

}
7 changes: 3 additions & 4 deletions lib/TEIShredder/PageGateway.php
Expand Up @@ -26,8 +26,8 @@

namespace TEIShredder;

use \InvalidArgumentException;
use \PDO;
use InvalidArgumentException;
use PDO;

/**
* Gateway class for page objects
Expand All @@ -42,7 +42,7 @@ class PageGateway extends AbstractGateway
{

/**
* {@inheritdoc}
* {@inheritDoc}
*/
protected function tableName()
{
Expand Down Expand Up @@ -121,5 +121,4 @@ public function find()
$properties = array_keys($page->toArray());
return parent::performFind(get_class($page), $properties, 'number', func_get_args());
}

}
9 changes: 3 additions & 6 deletions lib/TEIShredder/Section.php
Expand Up @@ -26,7 +26,7 @@

namespace TEIShredder;

use \LogicException;
use LogicException;

/**
* Model class for sections in the underlying TEI document.
Expand Down Expand Up @@ -58,7 +58,6 @@ class Section extends Model
* Volume number
*
* @var int
* @todo Redundant: a section starts on a page, and the page knows the volume
*/
protected $volume;

Expand Down Expand Up @@ -91,8 +90,7 @@ class Section extends Model
protected $element;

/**
* Section's opening tag's
* @xml:id attribute value
* Section's opening tag's @xml:id attribute value
* @var string
*/
protected $xmlid;
Expand All @@ -107,13 +105,12 @@ public function persistableData()
{
// Basic integrity check
foreach (array('id', 'volume', 'page', 'level', 'element') as $property) {
if (is_null($this->$property) or
if (is_null($this->$property) ||
'' === $this->$property
) {
throw new LogicException("Integrity check failed: $property cannot be empty.");
}
}
return $this->toArray();
}

}
9 changes: 4 additions & 5 deletions lib/TEIShredder/SectionGateway.php
Expand Up @@ -26,8 +26,8 @@

namespace TEIShredder;

use \InvalidArgumentException;
use \PDO;
use InvalidArgumentException;
use PDO;

/**
* Gateway for page objects
Expand All @@ -42,7 +42,7 @@ class SectionGateway extends AbstractGateway
{

/**
* {@inheritdoc}
* {@inheritDoc}
*/
protected function tableName()
{
Expand Down Expand Up @@ -88,5 +88,4 @@ public function find()
$properties = array_keys($section->toArray());
return parent::performFind(get_class($section), $properties, 'id', func_get_args());
}

}
}

0 comments on commit 48b9221

Please sign in to comment.