Skip to content

Commit

Permalink
feat: 增加 sucerr 函数,方便外部使用
Browse files Browse the repository at this point in the history
  • Loading branch information
twinh committed Feb 20, 2024
1 parent 1391fcb commit 475d121
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"Wei\\": "lib"
},
"files": [
"lib/Wei.php"
"lib/Wei.php",
"lib/functions.php"
]
},
"autoload-dev": {
Expand Down
31 changes: 31 additions & 0 deletions lib/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Wei\Ret;

if (!function_exists('suc')) {
/**
* Return operation successful result
*
* @param string|array|null $message
* @return Ret
*/
function suc($message = null): Ret
{
return Ret::suc($message);
}
}

if (!function_exists('err')) {
/**
* Return operation failed result, and logs with an info level
*
* @param array|string $message
* @param int|null $code
* @param string|null $level
* @return Ret
*/
function err($message, ?int $code = null, ?string $level = null): Ret
{
return Ret::err(...func_get_args());
}
}
6 changes: 6 additions & 0 deletions tests/unit/RetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -521,4 +521,10 @@ public function testAssertSuc()
$result = $ret->assert();
$this->assertSame($ret, $result);
}

public function testFn()
{
$this->assertRetSuc(suc());
$this->assertRetErr(err('x'));
}
}

0 comments on commit 475d121

Please sign in to comment.