Skip to content

Commit

Permalink
Apply php-cs-fixer
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Čihař <michal@cihar.com>
  • Loading branch information
nijel committed Jan 3, 2017
1 parent cf71d7c commit d29162c
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 124 deletions.
52 changes: 25 additions & 27 deletions src/Loader.php
Expand Up @@ -23,12 +23,13 @@

namespace MoTranslator;

class Loader {
class Loader
{
/**
* Loader instance
* Loader instance.
*
* @access private
* @static
*
* @var Loader
*/
private static $_instance;
Expand All @@ -48,36 +49,35 @@ class Loader {
private $locale = '';

/**
* Loaded domains
* Loaded domains.
*
* @var array
*/
private $domains = array();

/**
* Bound paths for domains
* Bound paths for domains.
*
* @var array
*/
private $paths = array('' => './');

/**
* Returns the singleton Loader object
* Returns the singleton Loader object.
*
* @return Loader object
*/
public static function getInstance()
{
if (empty(self::$_instance)) {
self::$_instance = new Loader();
self::$_instance = new self();
}

return self::$_instance;
}

/**
* Loads global localizaton functions.
*
* @return void
*/
public static function loadFunctions()
{
Expand All @@ -91,23 +91,23 @@ public static function loadFunctions()
*
* @param string $locale Locale code
*
* @return array list of locales to try for any POSIX-style locale specification.
* @return array list of locales to try for any POSIX-style locale specification
*/
public static function listLocales($locale) {
public static function listLocales($locale)
{
$locale_names = array();

$lang = NULL;
$country = NULL;
$charset = NULL;
$modifier = NULL;
$lang = null;
$country = null;
$charset = null;
$modifier = null;

if ($locale) {
if (preg_match('/^(?P<lang>[a-z]{2,3})' // language code
.'(?:_(?P<country>[A-Z]{2}))?' // country code
.'(?:\\.(?P<charset>[-A-Za-z0-9_]+))?' // charset
.'(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/', // @ modifier
. '(?:_(?P<country>[A-Z]{2}))?' // country code
. '(?:\\.(?P<charset>[-A-Za-z0-9_]+))?' // charset
. '(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/', // @ modifier
$locale, $matches)) {

extract($matches);

if ($modifier) {
Expand Down Expand Up @@ -137,11 +137,12 @@ public static function listLocales($locale) {
array_push($locale_names, $locale);
}
}

return $locale_names;
}

/**
* Returns Translator object for domain or for default domain
* Returns Translator object for domain or for default domain.
*
* @param string $domain Translation domain
*
Expand All @@ -154,7 +155,6 @@ public function getTranslator($domain = '')
}

if (!isset($this->domains[$domain])) {

if (isset($this->paths[$domain])) {
$base = $this->paths[$domain];
} else {
Expand Down Expand Up @@ -184,8 +184,6 @@ public function getTranslator($domain = '')
*
* @param string $domain Domain name
* @param string $path Path where to find locales
*
* @return void
*/
public function bindtextdomain($domain, $path)
{
Expand All @@ -196,16 +194,14 @@ public function bindtextdomain($domain, $path)
* Sets the default domain.
*
* @param string $domain Domain name
*
* @return void
*/
public function textdomain($domain)
{
$this->default_domain = $domain;
}

/**
* Sets a requested locale
* Sets a requested locale.
*
* @param string $locale Locale name
*
Expand All @@ -220,11 +216,12 @@ public function setlocale($locale)
setlocale(0, $locale);
}
}

return $this->locale;
}

/**
* Detects currently configured locale
* Detects currently configured locale.
*
* It checks:
*
Expand All @@ -244,6 +241,7 @@ public function detectlocale()
} elseif (getenv('LANG')) {
return getenv('LANG');
}

return 'en';
}
}
1 change: 1 addition & 0 deletions src/ReaderException.php
Expand Up @@ -19,6 +19,7 @@
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

namespace MoTranslator;

/**
Expand Down
28 changes: 17 additions & 11 deletions src/StringReader.php
Expand Up @@ -19,66 +19,72 @@
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

namespace MoTranslator;

/**
* Simple wrapper around string buffer for
* random access and values parsing.
*/
class StringReader {

class StringReader
{
private $_str;
private $_len;

/**
* Constructor
* Constructor.
*
* @param string $filename Name of file to load
*/
public function __construct($filename) {
public function __construct($filename)
{
$this->_str = file_get_contents($filename);
$this->_len = strlen($this->_str);
}

/**
* Read number of bytes from given offset
* Read number of bytes from given offset.
*
* @param int $pos Offset
* @param int $bytes Number of bytes to read
*
* @return string
*/
public function read($pos, $bytes) {
public function read($pos, $bytes)
{
if ($pos + $bytes > $this->_len) {
throw new ReaderException('Not enough bytes!');
}

return substr($this->_str, $pos, $bytes);
}

/**
* Reads a 32bit integer from the stream
* Reads a 32bit integer from the stream.
*
* @param string $unpack Unpack string
* @param int $pos Position
*
* @return int Ingerer from the stream
*/
public function readint($unpack, $pos) {
public function readint($unpack, $pos)
{
$data = unpack($unpack, $this->read($pos, 4));

return $data[1];
}

/**
* Reads an array of integers from the stream
* Reads an array of integers from the stream.
*
* @param string $unpack Unpack string
* @param int $pos Position
* @param int $count How many elements should be read
*
* @return array Array of Integers
*/
public function readintarray($unpack, $pos, $count) {
public function readintarray($unpack, $pos, $count)
{
return unpack($unpack . $count, $this->read($pos, 4 * $count));
}

}

0 comments on commit d29162c

Please sign in to comment.