@@ -25,13 +25,13 @@ class Converter
2525 public function __construct (string $ file , string $ fileType = null )
2626 {
2727 try {
28- $ file = new File ($ file );
29- } catch (\Exception $ e ) {
28+ $ file = new File ($ file, $ fileType );
29+ } catch (\Exception $ e ) {
3030 throw new ConverterException ($ e ->getMessage (), 1 );
3131 }
3232
33- foreach (self ::$ converters as $ converter ) {
34- if (!$ converter ::canHandleExtension ($ file ->getExtension ())) {
33+ foreach (self ::$ converters as $ converter ) {
34+ if (!$ converter ::canHandleExtension ($ file ->getType ())) {
3535 continue ;
3636 }
3737
@@ -40,8 +40,8 @@ public function __construct(string $file, string $fileType = null)
4040 break ;
4141 }
4242
43- if ($ this ->file === null ) {
44- throw new ConverterException ('Can not handle file type ' .$ file ->getExtension ());
43+ if ($ this ->file === null ) {
44+ throw new ConverterException ('Can not handle file type ' .$ file ->getType ());
4545 }
4646 }
4747
@@ -101,7 +101,7 @@ public function save(string $path, string $extension = null): bool
101101 }
102102
103103 if (!$ this ->isConvertableTo ($ extension )) {
104- throw new ConverterException ("Invalid conversion. Can not convert " .$ this ->file ->getExtension ()." to " .$ extension , 1 );
104+ throw new ConverterException ("Invalid conversion. Can not convert " .$ this ->file ->getType ()." to " .$ extension , 1 );
105105 }
106106
107107
@@ -122,7 +122,7 @@ public function save(string $path, string $extension = null): bool
122122 public function content (string $ extension = null ): string
123123 {
124124 if (!$ this ->isConvertableTo ($ extension )) {
125- throw new ConverterException ("Invalid conversion. Can not convert " .$ this ->file ->getExtension ()." to " .$ extension , 1 );
125+ throw new ConverterException ("Invalid conversion. Can not convert " .$ this ->file ->getType ()." to " .$ extension , 1 );
126126 }
127127
128128 $ tempDir = (new TemporaryDirectory (__DIR__ ))
@@ -143,6 +143,10 @@ public function content(string $extension = null): string
143143
144144 protected function getNewFilename (string $ extension )
145145 {
146+ if ($ this ->file ->getExtension () === null ) {
147+ return $ this ->file ->getName () . '. ' . $ extension ;
148+ }
149+
146150 return str_replace ($ this ->file ->getExtension (), $ extension , $ this ->file ->getName ());
147151 }
148152
0 commit comments