UploadEntityName::lang()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Mostafaznv\Larupload\Concerns\Storage\UploadEntity;
4
5
use Illuminate\Http\UploadedFile;
6
use Illuminate\Support\Str;
7
use Mostafaznv\Larupload\Enums\LaruploadNamingMethod;
8
use Mostafaznv\Larupload\Helpers\Slug;
9
use Mostafaznv\Larupload\Larupload;
10
use Mostafaznv\Larupload\UploadEntities;
11
12
trait UploadEntityName
13
{
14
    /**
15
     * Name of file
16
     */
17
    protected string $name;
18
19
    /**
20
     * Name of file in kebab case
21
     */
22
    protected string $nameKebab;
23
24
    /**
25
     * Specify the method that Larupload should use to name uploaded files.
26
     */
27
    protected LaruploadNamingMethod $namingMethod;
28
29
    /**
30
     * Language of file name
31
     */
32
    protected ?string $lang;
33
34
35
    public function getName(bool $withNameStyle = false): string
36
    {
37
        return $withNameStyle ? $this->nameStyle($this->name) : $this->name;
38
    }
39
40
    public function namingMethod(LaruploadNamingMethod $method): UploadEntities
41
    {
42
        $this->namingMethod = $method;
43
44
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Mostafaznv\Larupload\Con...Entity\UploadEntityName which includes types incompatible with the type-hinted return Mostafaznv\Larupload\UploadEntities.
Loading history...
45
    }
46
47
    public function lang(string $lang): UploadEntities
48
    {
49
        $this->lang = $lang;
50
51
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Mostafaznv\Larupload\Con...Entity\UploadEntityName which includes types incompatible with the type-hinted return Mostafaznv\Larupload\UploadEntities.
Loading history...
52
    }
53
54
    /**
55
     * Check whether we should convert the name to camel-case style.
56
     */
57
    protected function nameStyle($name): string
58
    {
59
        return $this->camelCaseResponse ? Str::camel($name) : $name;
60
    }
61
}
62