Skip to content

Commit

Permalink
Merge pull request #6 from lion-packages/bug
Browse files Browse the repository at this point in the history
Correction of the join method of the Arr class
  • Loading branch information
Sleon4 authored Feb 13, 2024
2 parents 3479914 + 0750a50 commit 5ccb8be
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Lion-Packages
Copyright (c) 2022 Lion-Packages

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
</p>

## Install

```bash
composer require lion/helpers
```
Expand Down
4 changes: 4 additions & 0 deletions src/LionHelpers/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ public function join(string $separator = ', ', ?string $lastSeparator = null): s
return implode($separator, $items);
}

if (count($items) <= 1) {
return implode($separator, $items);
}

$lastElement = array_pop($items);

return implode($separator, $items) . "{$lastSeparator}{$lastElement}";
Expand Down
6 changes: 6 additions & 0 deletions tests/Providers/ArrProviderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ public static function joinProvider(): array
'separator' => ', ',
'lastSeparator' => null,
'return' => 'root'
],
[
'elements' => self::NAMES,
'separator' => ', ',
'lastSeparator' => ' and ',
'return' => 'root'
]
];
}
Expand Down

0 comments on commit 5ccb8be

Please sign in to comment.