@@ -35,18 +35,13 @@ trait BackupTrait
3535 protected static $ validExtensions = ['sql.bz2 ' => 'bzip2 ' , 'sql.gz ' => 'gzip ' , 'sql ' => false ];
3636
3737 /**
38- * Returns an absolute path
38+ * Returns the absolute path for a backup file
3939 * @param string $path Relative or absolute path
4040 * @return string
4141 */
42- public function getAbsolutePath (string $ path ): string
42+ public static function getAbsolutePath (string $ path ): string
4343 {
44- $ Filesystem = new Filesystem ();
45- if (!$ Filesystem ->isAbsolutePath ($ path )) {
46- return $ Filesystem ->addSlashTerm (Configure::read ('DatabaseBackup.target ' )) . $ path ;
47- }
48-
49- return $ path ;
44+ return Filesystem::instance ()->makePathAbsolute ($ path , Configure::read ('DatabaseBackup.target ' ));
5045 }
5146
5247 /**
@@ -56,13 +51,11 @@ public function getAbsolutePath(string $path): string
5651 * @uses getExtension()
5752 * @uses getValidCompressions()
5853 */
59- public function getCompression (string $ filename ): ?string
54+ public static function getCompression (string $ filename ): ?string
6055 {
61- //Gets the extension from the filename
62- $ extension = $ this ->getExtension ($ filename );
63- $ keyExists = array_key_exists ($ extension , $ this ->getValidCompressions ());
56+ $ extension = self ::getExtension ($ filename );
6457
65- return $ keyExists ? $ this -> getValidCompressions ()[$ extension ] : null ;
58+ return self :: getValidCompressions ()[$ extension ] ?? null ;
6659 }
6760
6861 /**
@@ -79,7 +72,7 @@ public function getConnection(?string $name = null): ConnectionInterface
7972 * Gets the driver instance containing all methods to export/import database
8073 * backups, according to the database engine
8174 * @param \Cake\Datasource\ConnectionInterface|null $connection A connection object
82- * @return object The driver instance
75+ * @return \DatabaseBackup\Driver\Driver A driver instance
8376 * @since 2.0.0
8477 * @throws \InvalidArgumentException
8578 * @uses getConnection()
@@ -101,20 +94,20 @@ public function getDriver(?ConnectionInterface $connection = null): object
10194 * if is an invalid extension
10295 * @uses $validExtensions
10396 */
104- public function getExtension (string $ filename ): ?string
97+ public static function getExtension (string $ filename ): ?string
10598 {
106- $ extension = ( new Filesystem () )->getExtension ($ filename );
99+ $ extension = Filesystem:: instance ( )->getExtension ($ filename );
107100
108101 return in_array ($ extension , array_keys (self ::$ validExtensions )) ? $ extension : null ;
109102 }
110103
111104 /**
112105 * Returns all valid compressions
113- * @return array
106+ * @return array<string, string>
114107 * @since 2.4.0
115108 * @uses $validExtensions
116109 */
117- public function getValidCompressions (): array
110+ public static function getValidCompressions (): array
118111 {
119112 return array_filter (self ::$ validExtensions );
120113 }
0 commit comments