Skip to content

Commit 99f4462

Browse files
committed
fix bugs
1 parent c54f404 commit 99f4462

File tree

5 files changed

+29
-31
lines changed

5 files changed

+29
-31
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
All notable changes to `dvlpr1996/php-string-helpers` will be documented in this file
44

5-
## 0.1.0
5+
## 0.1.0 (2022-11-23)
66

77
- initial release

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
55
[![Latest Version on Packagist](https://img.shields.io/packagist/v/dvlpr1996/php-string-helpers?style=flat)](https://packagist.org/packages/dvlpr1996/php-string-helpers)
6-
[![Total Downloads](https://img.shields.io/packagist/dt/dvlpr1996/php-string-helpers.svg?style=flat-square)](https://packagist.org/packages/dvlpr1996/php-string-helpers)
6+
[![Total Downloads](https://img.shields.io/packagist/dt/dvlpr1996/php-string-helpers)](https://packagist.org/packages/dvlpr1996/php-string-helpers)
77

88
All function helpers will be enabled by default (if those functions haven't already been defined).
99
also you can use them as utilities class.

composer.lock

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/utility/StrUtility.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ public static function alternate(?string $string, string $alternate = null): str
196196
public static function translate(string $key, string $replace = '', string $dirName = 'en'): string
197197
{
198198
$fileName = explode('.', $key);
199+
$key = $fileName[1];
199200
$filePath = self::filePath('lang.' . $dirName . '.' . $fileName[0]);
200201

201202
if (!is_file($filePath) || !file_exists($filePath))
@@ -240,11 +241,14 @@ public static function wrapper(int|string $string, int|string $wrapper = '*'): s
240241
*/
241242
public static function filePath(string $path, string $pathExtension = 'php'): string
242243
{
243-
$path = getcwd() . '/' . str_replace(".", "/", implode(".", explode('.', $path)));
244+
245+
$path = $_SERVER['DOCUMENT_ROOT'] .
246+
str_replace('.', '/', implode('.', explode('.', $path)));
247+
244248
$filePath = $path . '.' . strtolower($pathExtension);
245249

246250
if (!is_file($filePath) || !file_exists($filePath))
247-
throw new FileDoesNotExistsException("File Does Not Exist");
251+
throw new FileDoesNotExistsException('File Does Not Exist');
248252

249253
return $filePath;
250254
}

tests/StrUtilityTest.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public function testAlternateCanReturnStringValueIfBothParamAreNull()
203203

204204
public function testTranslateCanReturnStringData()
205205
{
206-
$string = strHelpersTest::translate('auth.user_name');
206+
$string = strHelpersTest::translate('app.title');
207207
$this->assertIsString($string);
208208
}
209209

@@ -219,23 +219,17 @@ public function testTranslateCanThrowExceptionIfLangFileDoesNotInArrayType()
219219
$string = strHelpersTest::translate('app.title');
220220
}
221221

222-
public function testTranslateCanReturnReplaceParamIfKeyDoesNotExists()
223-
{
224-
$string = strHelpersTest::translate('app.Title', 'laravel');
225-
$this->assertEquals('laravel', $string);
226-
}
227-
228222
public function testFilePathCanReturnStringValue()
229223
{
230-
$filePath = strHelpersTest::filePath('lang.en.auth.auth');
224+
$filePath = strHelpersTest::filePath('lang.en.app');
231225
$this->assertIsString($filePath);
232226
}
233227

234-
public function testFilePathReturnedFilePathIsExists()
228+
public function testFilePathReturnedFilePathIfExists()
235229
{
236-
$filePath = strHelpersTest::filePath('lang.en.auth.auth');
230+
$filePath = strHelpersTest::filePath('lang.en.app');
237231
$this->assertFileExists($filePath);
238-
$this->assertFileEquals('lang/en/auth/auth.php', $filePath);
232+
$this->assertFileEquals('lang/en/app.php', $filePath);
239233
$this->assertFileIsReadable($filePath);
240234
}
241235

@@ -361,13 +355,13 @@ public function testLimitCharCanReturnStringValue()
361355
public function testLimitCharCanLimitGivenString()
362356
{
363357
$string = strHelpersTest::limitChar('foo bar', 2);
364-
$this->assertEquals('foo b...',$string);
358+
$this->assertEquals('foo b...', $string);
365359
}
366360

367361
public function testLimitCharCanReturnGivenStringIfLengthParamIsBiggerThanStringLength()
368362
{
369363
$string = strHelpersTest::limitChar('foo bar', 8);
370-
$this->assertEquals('foo bar',$string);
364+
$this->assertEquals('foo bar', $string);
371365
}
372366

373367
public function testGenerateIdCanReturnStringValue()

0 commit comments

Comments
 (0)