Skip to content

Commit

Permalink
Add mb_str_functions to php_cs and applied to files
Browse files Browse the repository at this point in the history
  • Loading branch information
athk committed Sep 1, 2017
1 parent 05a692a commit 0f37a18
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 26 deletions.
1 change: 1 addition & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ return PhpCsFixer\Config::create()
'standardize_not_equals' => true,
'ternary_operator_spaces' => true,
'trim_array_spaces' => true,
'mb_str_functions' => true,
//'doctrine_annotation_spaces' => true,
])
->setFinder($finder);
2 changes: 1 addition & 1 deletion app/Commands/DeployAssetsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected function configure()
{
$this->setName('app:assets:deploy-css')
->setDescription('Deploys css assets and generates an updated css-manifest.json')
->setHelp('This command allows you to copy and deploy assets to the public folder,' .
->setHelp('This command allows you to copy and deploy assets to the public folder,'.
'generating a mapping between asset names and their public folder at rev-manifest.json');
}

Expand Down
2 changes: 1 addition & 1 deletion app/Controllers/DownloadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function download($id, RequestInterface $request, ResponseInterface $resp
}

$file .= $text;
if (substr($text, strlen($text) - 1) != "\n") {
if (mb_substr($text, mb_strlen($text) - 1) != "\n") {
$file .= "\r\n"; // Add a linebreak if there's none in this last line
}

Expand Down
7 changes: 3 additions & 4 deletions app/Controllers/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,21 @@ public function query($request, $response, EntityManager $em, \Elasticsearch\Cli

$shows = [];

if (strlen($q) > 3) {
if (mb_strlen($q) > 3) {
$episode = $season = -1;

if (\preg_match('/(\d+)x(\d+)?|S(\d+)E?(\d+)?/i', $q, $matches)) {
// We may have episode & season
$season = isset($matches[1]) ? (int)$matches[1] : (isset($matches[3]) ? (int)$matches[3] : -1);
$episode = isset($matches[2]) ? (int)$matches[2] : (isset($matches[4]) ? (int)$matches[4] : -1);
$showName = trim(str_replace($matches[0], '', $q));
}
else {
} else {
// No episode in search
$showName = $q;
}

$r = $client->search([
'index' => ELASTICSEARCH_NAMESPACE . '_shows',
'index' => ELASTICSEARCH_NAMESPACE.'_shows',
'type' => 'show',
'body' => [
'query' => [
Expand Down
22 changes: 11 additions & 11 deletions app/Services/AssetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@ class AssetManager
* Path of the asset directory
* @var string
*/
public const ASSET_PATH = __DIR__ . '/../../resources/assets';
public const ASSET_PATH = __DIR__.'/../../resources/assets';

/**
* Path of the manifest file
* @var string
*/
public const CSS_MANIFEST_PATH = self::ASSET_PATH . '/css-manifest.json';
public const CSS_MANIFEST_PATH = self::ASSET_PATH.'/css-manifest.json';

/**
* Path of the manifest file
* @var string
*/
public const WEBPACK_MANIFEST_PATH = self::ASSET_PATH . '/manifest.json';
public const WEBPACK_MANIFEST_PATH = self::ASSET_PATH.'/manifest.json';

/**
* Path of the deploy directory
* @var string
*/
public const DEPLOY_PATH = __DIR__ . '/../../public';
public const DEPLOY_PATH = __DIR__.'/../../public';

public function __construct()
{
Expand Down Expand Up @@ -77,7 +77,7 @@ public function loadManifest()
public function redeployCSS()
{
$manifest = [];
foreach (new \DirectoryIterator(self::ASSET_PATH . '/css') as $fileInfo) {
foreach (new \DirectoryIterator(self::ASSET_PATH.'/css') as $fileInfo) {
$ext = $fileInfo->getExtension();

if ($fileInfo->isDot() || !$fileInfo->isFile() || !\in_array($fileInfo->getExtension(), ['css'])) {
Expand All @@ -86,12 +86,12 @@ public function redeployCSS()

$fileName = $fileInfo->getFilename();
$fullPath = $fileInfo->getPathname();
$ver = substr(hash_file('md5', $fullPath), 0, 8);
$ver = mb_substr(hash_file('md5', $fullPath), 0, 8);

$newName = str_replace('.' . $ext, '', $fileName) . '-' . $ver . '.' . $ext;
\copy(self::DEPLOY_PATH . '/css/' . $fileName, self::DEPLOY_PATH . '/css/' . $newName);
$newName = str_replace('.'.$ext, '', $fileName).'-'.$ver.'.'.$ext;
\copy(self::DEPLOY_PATH.'/css/'.$fileName, self::DEPLOY_PATH.'/css/'.$newName);

$manifest[$fileName] = 'css/' . $newName;
$manifest[$fileName] = 'css/'.$newName;
}

\file_put_contents(self::CSS_MANIFEST_PATH, \json_encode($manifest));
Expand All @@ -101,8 +101,8 @@ public function redeployCSS()
public function getCssVersionedName($assetName)
{
if (DEBUG === true) {
$v = feature_on('DEBUG_CSS_NOCACHE') !== true ? substr(hash_file('md5', self::ASSET_PATH . '/css/' . $assetName), 0, 8) : time();
return 'css/' . $assetName . '?v=' . $v;
$v = feature_on('DEBUG_CSS_NOCACHE') !== true ? mb_substr(hash_file('md5', self::ASSET_PATH.'/css/'.$assetName), 0, 8) : time();
return 'css/'.$assetName.'?v='.$v;
}

return isset($this->cssManifest[$assetName]) ? $this->cssManifest[$assetName] : 'err';
Expand Down
14 changes: 6 additions & 8 deletions app/Services/Translation.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public function broadcastUserInfo(Subtitle $sub, User $u)
*/
public function setWSAuthToken(string $token, Subtitle $sub)
{
$this->redis->set('authtok-' . ENVIRONMENT_NAME . '-' . $token, $sub->getId(), 24 * 60 * 60);
$this->redis->set('authtok-'.ENVIRONMENT_NAME.'-'.$token, $sub->getId(), 24 * 60 * 60);
}

/**
Expand All @@ -243,12 +243,11 @@ public function recalculateSubtitleProgress($baseSub, Subtitle $sub, int $modifi
->setParameter('sub', $sub->getId())
->getSingleScalarResult();

$sub->setProgress( ($ourSubSeqCount + $modifier) / $baseSubSeqCount * 100);
$sub->setProgress(($ourSubSeqCount + $modifier) / $baseSubSeqCount * 100);
if ($sub->getProgress() == 100 && !$sub->getPause()) {
// We're done! Mark as such
$sub->setCompleteTime(new \DateTime());
}
elseif ($sub->getCompleteTime()) {
} elseif ($sub->getCompleteTime()) {
$sub->setCompleteTime(null);
}
}
Expand Down Expand Up @@ -310,7 +309,7 @@ public static function cleanText(string $text, bool $allowSpecialTags)
// Remove multiple spaces concatenated / trim each line
$lines = explode("\n", $text);
foreach ($lines as &$line) {
$line = \substr(trim(preg_replace('/ +/', ' ', $line)), 0, 40);
$line = \mb_substr(trim(preg_replace('/ +/', ' ', $line)), 0, 40);
}

// Make sure that we only have two lines, and convert them back to string
Expand All @@ -321,7 +320,7 @@ public static function cleanText(string $text, bool $allowSpecialTags)
$text = strip_tags($text, '<font>');

$dom = new \DOMDocument();
$dom->loadHTML(mb_convert_encoding('<div>' . $text . '</div>', 'HTML-ENTITIES', 'UTF-8'), \LIBXML_HTML_NOIMPLIED | \LIBXML_HTML_NODEFDTD);
$dom->loadHTML(mb_convert_encoding('<div>'.$text.'</div>', 'HTML-ENTITIES', 'UTF-8'), \LIBXML_HTML_NOIMPLIED | \LIBXML_HTML_NODEFDTD);

$xpath = new \DOMXPath($dom);
$nodes = $xpath->query('//font');
Expand All @@ -338,8 +337,7 @@ public static function cleanText(string $text, bool $allowSpecialTags)
}

$text = trim(Encoding::toUTF8(\html_entity_decode(strip_tags($dom->saveHTML($dom->documentElement), '<font>'))));
}
else {
} else {
$text = strip_tags($text);
}

Expand Down
2 changes: 1 addition & 1 deletion app/Services/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Utils
public static function generateRandomString(int $length, $charPool = 'abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ-')
{
$tok = '';
$max = strlen($charPool);
$max = mb_strlen($charPool);

while ($length--) {
$tok .= $charPool[mt_rand(0, $max - 1)];
Expand Down

0 comments on commit 0f37a18

Please sign in to comment.