From 38b3c108bf4ebccd8f64f0a84c61c66414c926b5 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Tue, 11 Nov 2025 12:55:23 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Use=20`replacing(with:)`?= =?UTF-8?q?=20instead=20of=20`.replacingOccurrences(of:with:)`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The newer Swift native method is broadly supported and can properly handle complex UTF-8 characters like emoji, whereas the old API does not work correctly with emoji. In most cases, this likely wouldn't have caused any issues but it does make things a little cleaner now, and ensures we won't encounter emoji trouble in the future. --- PHP Monitor.xcodeproj/project.pbxproj | 16 ++++++++-------- phpmon/Common/Core/Helpers.swift | 4 ++-- phpmon/Common/Extensions/StringExtension.swift | 2 +- phpmon/Common/Filesystem/RealFileSystem.swift | 10 +++++++--- .../Common/PHP/Homebrew/HomebrewDecodable.swift | 2 +- phpmon/Common/PHP/PHP Version/PhpHelper.swift | 2 +- phpmon/Common/PHP/PhpConfigurationFile.swift | 4 ++-- phpmon/Common/PHP/PhpExtension.swift | 6 +++--- .../PHP/Switcher/InternalSwitcher+Valet.swift | 4 ++-- .../Common/PHP/Switcher/InternalSwitcher.swift | 2 +- phpmon/Common/Testables/TestableFileSystem.swift | 6 +++--- phpmon/Domain/App/AppDelegate+InterApp.swift | 2 +- phpmon/Domain/App/AppDelegate.swift | 2 +- phpmon/Domain/App/AppUpdater.swift | 2 +- phpmon/Domain/App/Startup.swift | 4 ++-- phpmon/Domain/Integrations/Common/RCFile.swift | 4 ++-- .../Integrations/Homebrew/BrewDiagnostics.swift | 2 +- .../Integrations/Homebrew/BrewPhpExtension.swift | 4 ++-- .../Integrations/Homebrew/BrewPhpFormula.swift | 8 ++++---- .../Homebrew/BrewPhpFormulaeHandler.swift | 4 ++-- .../PHP Versions/RemovePhpVersionCommand.swift | 4 ++-- .../Nginx/NginxConfigurationFile.swift | 4 ++-- .../Valet/Sites/CertificateValidator.swift | 8 ++++---- .../Integrations/Valet/Sites/ValetSite.swift | 2 +- phpmon/Modules/Domain List/UI/AddProxyVC.swift | 4 ++-- phpmon/Modules/Domain List/UI/AddSiteVC.swift | 2 +- .../Filesystem/RealFileSystemTest.swift | 2 +- 27 files changed, 60 insertions(+), 56 deletions(-) diff --git a/PHP Monitor.xcodeproj/project.pbxproj b/PHP Monitor.xcodeproj/project.pbxproj index 6db4e48b..63e3ec09 100644 --- a/PHP Monitor.xcodeproj/project.pbxproj +++ b/PHP Monitor.xcodeproj/project.pbxproj @@ -3920,7 +3920,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1695; + CURRENT_PROJECT_VERSION = 1697; DEAD_CODE_STRIPPING = YES; DEBUG = YES; ENABLE_APP_SANDBOX = NO; @@ -3939,7 +3939,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 13.5; - MARKETING_VERSION = 25.10.2; + MARKETING_VERSION = 25.10.3; PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon; PRODUCT_MODULE_NAME = PHP_Monitor; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -3964,7 +3964,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1695; + CURRENT_PROJECT_VERSION = 1697; DEAD_CODE_STRIPPING = YES; DEBUG = NO; ENABLE_APP_SANDBOX = NO; @@ -3983,7 +3983,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 13.5; - MARKETING_VERSION = 25.10.2; + MARKETING_VERSION = 25.10.3; PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon; PRODUCT_MODULE_NAME = PHP_Monitor; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -4146,7 +4146,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1695; + CURRENT_PROJECT_VERSION = 1697; DEAD_CODE_STRIPPING = YES; DEBUG = YES; ENABLE_APP_SANDBOX = NO; @@ -4165,7 +4165,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 13.5; - MARKETING_VERSION = 25.10.2; + MARKETING_VERSION = 25.10.3; PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon.eap; PRODUCT_MODULE_NAME = PHP_Monitor; PRODUCT_NAME = "$(TARGET_NAME) EAP"; @@ -4339,7 +4339,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1695; + CURRENT_PROJECT_VERSION = 1697; DEAD_CODE_STRIPPING = YES; DEBUG = NO; ENABLE_APP_SANDBOX = NO; @@ -4358,7 +4358,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 13.5; - MARKETING_VERSION = 25.10.2; + MARKETING_VERSION = 25.10.3; PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon.eap; PRODUCT_MODULE_NAME = PHP_Monitor; PRODUCT_NAME = "$(TARGET_NAME) EAP"; diff --git a/phpmon/Common/Core/Helpers.swift b/phpmon/Common/Core/Helpers.swift index 50e76d49..0e0909e9 100644 --- a/phpmon/Common/Core/Helpers.swift +++ b/phpmon/Common/Core/Helpers.swift @@ -31,8 +31,8 @@ func sed( replacement: String ) async { // Escape slashes (or `sed` won't work) - let e_original = original.replacingOccurrences(of: "/", with: "\\/") - let e_replacement = replacement.replacingOccurrences(of: "/", with: "\\/") + let e_original = original.replacing("/", with: "\\/") + let e_replacement = replacement.replacing("/", with: "\\/") // Check if gsed exists; it is able to follow symlinks, // which we want to do to toggle the extension diff --git a/phpmon/Common/Extensions/StringExtension.swift b/phpmon/Common/Extensions/StringExtension.swift index bc76727b..085e9676 100644 --- a/phpmon/Common/Extensions/StringExtension.swift +++ b/phpmon/Common/Extensions/StringExtension.swift @@ -65,7 +65,7 @@ extension String { return NSLocalizedString(self, bundle: bundle, comment: "") } - return string.replacingOccurrences(of: "Preferences", with: "Settings") + return string.replacing("Preferences", with: "Settings") } var localizedForSwiftUI: LocalizedStringKey { diff --git a/phpmon/Common/Filesystem/RealFileSystem.swift b/phpmon/Common/Filesystem/RealFileSystem.swift index 7f803bd2..1a780d07 100644 --- a/phpmon/Common/Filesystem/RealFileSystem.swift +++ b/phpmon/Common/Filesystem/RealFileSystem.swift @@ -12,11 +12,15 @@ extension String { var replacingTildeWithHomeDirectory: String { // Try and check if there's a shared container if let paths = App.shared.container.paths { - return self.replacingOccurrences(of: "~", with: paths.homePath) + return self.replacing("~", with: paths.homePath) } - // TODO: Come up with some other way to handle this when the app container is not available, especially for tests - return self + // It's also okay if we're running tests + if isRunningTests { + return self + } + + fatalError("The app container is not available, the home directory could not be inferred.") } } diff --git a/phpmon/Common/PHP/Homebrew/HomebrewDecodable.swift b/phpmon/Common/PHP/Homebrew/HomebrewDecodable.swift index 23ef0bc0..136aa4a1 100644 --- a/phpmon/Common/PHP/Homebrew/HomebrewDecodable.swift +++ b/phpmon/Common/PHP/Homebrew/HomebrewDecodable.swift @@ -15,7 +15,7 @@ struct HomebrewPackage: Decodable { public var version: String { return aliases.first! - .replacingOccurrences(of: "php@", with: "") + .replacing("php@", with: "") } } diff --git a/phpmon/Common/PHP/PHP Version/PhpHelper.swift b/phpmon/Common/PHP/PHP Version/PhpHelper.swift index 84795437..5a6b2eb4 100644 --- a/phpmon/Common/PHP/PHP Version/PhpHelper.swift +++ b/phpmon/Common/PHP/PHP Version/PhpHelper.swift @@ -16,7 +16,7 @@ class PhpHelper { for version: String ) async { // Take the PHP version (e.g. "7.2") and generate a dotless version - let dotless = version.replacingOccurrences(of: ".", with: "") + let dotless = version.replacing(".", with: "") // Determine the dotless name for this PHP version let destination = "\(container.paths.homePath)/.config/phpmon/bin/pm\(dotless)" diff --git a/phpmon/Common/PHP/PhpConfigurationFile.swift b/phpmon/Common/PHP/PhpConfigurationFile.swift index e13d8418..8e000413 100644 --- a/phpmon/Common/PHP/PhpConfigurationFile.swift +++ b/phpmon/Common/PHP/PhpConfigurationFile.swift @@ -36,7 +36,7 @@ class PhpConfigurationFile: CreatedFromFile { _ container: Container, filePath: String ) -> Self? { - let path = filePath.replacingOccurrences(of: "~", with: container.paths.homePath) + let path = filePath.replacing("~", with: container.paths.homePath) do { let fileContents = try container.filesystem.getStringFromFile(path) @@ -96,7 +96,7 @@ class PhpConfigurationFile: CreatedFromFile { // Replace the value with the new one components[1] = components[1] - .replacingOccurrences(of: item.value, with: value) + .replacing(item.value, with: value) // Replace the specific line self.lines[item.lineIndex] = components.joined(separator: "=") diff --git a/phpmon/Common/PHP/PhpExtension.swift b/phpmon/Common/PHP/PhpExtension.swift index a4a950a5..3c80e8b7 100644 --- a/phpmon/Common/PHP/PhpExtension.swift +++ b/phpmon/Common/PHP/PhpExtension.swift @@ -70,8 +70,8 @@ class PhpExtension { self.line = line let fullPath = String(line[range]) - .replacingOccurrences(of: "\"", with: "") // replace excess " - .replacingOccurrences(of: ".so", with: "") // replace excess .so + .replacing("\"", with: "") // replace excess " + .replacing(".so", with: "") // replace excess .so self.name = String(fullPath.split(separator: "/").last!) // take last segment @@ -88,7 +88,7 @@ class PhpExtension { // DISABLED: Commented out line ? "; \(line)" // ENABLED: Line where the comment delimiter (;) is removed - : line.replacingOccurrences(of: "; ", with: "") + : line.replacing("; ", with: "") await sed(container, file: file, original: line, replacement: newLine) diff --git a/phpmon/Common/PHP/Switcher/InternalSwitcher+Valet.swift b/phpmon/Common/PHP/Switcher/InternalSwitcher+Valet.swift index b3c021c7..32c5747d 100644 --- a/phpmon/Common/PHP/Switcher/InternalSwitcher+Valet.swift +++ b/phpmon/Common/PHP/Switcher/InternalSwitcher+Valet.swift @@ -74,7 +74,7 @@ extension InternalSwitcher { var contents = try container.filesystem.getStringFromFile("~/.composer/vendor/laravel/valet" + file.source) for (original, replacement) in file.replacements { - contents = contents.replacingOccurrences(of: original, with: replacement) + contents = contents.replacing(original, with: replacement) } try container.filesystem.writeAtomicallyToFile( @@ -103,7 +103,7 @@ extension InternalSwitcher { replacements: [ "VALET_USER": container.paths.whoami, "VALET_HOME_PATH": "~/.config/valet".replacingTildeWithHomeDirectory, - "valet.sock": "valet\(version.replacingOccurrences(of: ".", with: "")).sock" + "valet.sock": "valet\(version.replacing(".", with: "")).sock" ], applies: { Valet.shared.version!.major > 2 } ), diff --git a/phpmon/Common/PHP/Switcher/InternalSwitcher.swift b/phpmon/Common/PHP/Switcher/InternalSwitcher.swift index 4c443bca..09058527 100644 --- a/phpmon/Common/PHP/Switcher/InternalSwitcher.swift +++ b/phpmon/Common/PHP/Switcher/InternalSwitcher.swift @@ -111,7 +111,7 @@ class InternalSwitcher: PhpSwitcher { await brew(container, "services start \(formula)", sudo: true) if Valet.enabled(feature: .isolatedSites) && primary { - let socketVersion = version.replacingOccurrences(of: ".", with: "") + let socketVersion = version.replacing(".", with: "") await container.shell.quiet("ln -sF ~/.config/valet/valet\(socketVersion).sock ~/.config/valet/valet.sock") Log.info("Symlinked new socket version (valet\(socketVersion).sock → valet.sock).") } diff --git a/phpmon/Common/Testables/TestableFileSystem.swift b/phpmon/Common/Testables/TestableFileSystem.swift index 7a24e3ca..20ab6f6e 100644 --- a/phpmon/Common/Testables/TestableFileSystem.swift +++ b/phpmon/Common/Testables/TestableFileSystem.swift @@ -20,7 +20,7 @@ class TestableFileSystem: FileSystemProtocol { // Ensure that each of the ~ characters are replaced with the home directory path accessQueue.sync { for (key, value) in files { - let adjustedKey = key.contains("~") ? key.replacingOccurrences(of: "~", with: self.homeDirectory) : key + let adjustedKey = key.contains("~") ? key.replacing("~", with: self.homeDirectory) : key self.files[adjustedKey] = value } @@ -102,7 +102,7 @@ class TestableFileSystem: FileSystemProtocol { return accessQueue.sync { self.files.keys .filter { $0.hasPrefix(seek) } - .map { $0.replacingOccurrences(of: seek, with: "") } + .map { $0.replacing(seek, with: "") } .filter { !$0.contains("/") } } } @@ -142,7 +142,7 @@ class TestableFileSystem: FileSystemProtocol { if key.hasPrefix(path) { self.files.renameKey( fromKey: key, - toKey: key.replacingOccurrences(of: path, with: newPath) + toKey: key.replacing(path, with: newPath) ) } } diff --git a/phpmon/Domain/App/AppDelegate+InterApp.swift b/phpmon/Domain/App/AppDelegate+InterApp.swift index 7296e766..a3cec555 100644 --- a/phpmon/Domain/App/AppDelegate+InterApp.swift +++ b/phpmon/Domain/App/AppDelegate+InterApp.swift @@ -29,7 +29,7 @@ extension AppDelegate { guard let url = urls.first else { return } self.interpretCommand( - url.absoluteString.replacingOccurrences(of: "phpmon://", with: ""), + url.absoluteString.replacing("phpmon://", with: ""), commands: InterApp.getCommands() ) } diff --git a/phpmon/Domain/App/AppDelegate.swift b/phpmon/Domain/App/AppDelegate.swift index b05ca808..b838faee 100644 --- a/phpmon/Domain/App/AppDelegate.swift +++ b/phpmon/Domain/App/AppDelegate.swift @@ -54,7 +54,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele #if DEBUG logger.verbosity = .performance if let profile = CommandLine.arguments.first(where: { $0.matches(pattern: "--configuration:*") }) { - AppDelegate.initializeTestingProfile(profile.replacingOccurrences(of: "--configuration:", with: "")) + AppDelegate.initializeTestingProfile(profile.replacing("--configuration:", with: "")) } #endif diff --git a/phpmon/Domain/App/AppUpdater.swift b/phpmon/Domain/App/AppUpdater.swift index e27dbadf..6a128d97 100644 --- a/phpmon/Domain/App/AppUpdater.swift +++ b/phpmon/Domain/App/AppUpdater.swift @@ -148,7 +148,7 @@ class AppUpdater { system_quiet("mkdir -p ~/.config/phpmon/updater 2> /dev/null") let updaterDirectory = "~/.config/phpmon/updater" - .replacingOccurrences(of: "~", with: NSHomeDirectory()) + .replacing("~", with: NSHomeDirectory()) system_quiet("cp -R \"\(updater)\" \"\(updaterDirectory)/PHP Monitor Self-Updater.app\"") diff --git a/phpmon/Domain/App/Startup.swift b/phpmon/Domain/App/Startup.swift index dd5584fd..897c6fdb 100644 --- a/phpmon/Domain/App/Startup.swift +++ b/phpmon/Domain/App/Startup.swift @@ -97,8 +97,8 @@ class Startup { subtitleText: "alert.homebrew_missing.subtitle".localized, descriptionText: "alert.homebrew_missing.info".localized( App.architecture - .replacingOccurrences(of: "x86_64", with: "Intel") - .replacingOccurrences(of: "arm64", with: "Apple Silicon"), + .replacing("x86_64", with: "Intel") + .replacing("arm64", with: "Apple Silicon"), App.shared.container.paths.brew ), buttonText: "alert.homebrew_missing.quit".localized, diff --git a/phpmon/Domain/Integrations/Common/RCFile.swift b/phpmon/Domain/Integrations/Common/RCFile.swift index 52a34e4f..84057f24 100644 --- a/phpmon/Domain/Integrations/Common/RCFile.swift +++ b/phpmon/Domain/Integrations/Common/RCFile.swift @@ -31,13 +31,13 @@ struct RCFile { let content = line.split(separator: "=") let key = String(content[0]) .trimmingCharacters(in: .whitespaces) - .replacingOccurrences(of: "\"", with: "") + .replacing("\"", with: "") if key.starts(with: "#") { return } let value = String(content[1]) .trimmingCharacters(in: .whitespaces) - .replacingOccurrences(of: "\"", with: "") + .replacing("\"", with: "") fields[key] = value } }) diff --git a/phpmon/Domain/Integrations/Homebrew/BrewDiagnostics.swift b/phpmon/Domain/Integrations/Homebrew/BrewDiagnostics.swift index 7989567d..0c610f8f 100644 --- a/phpmon/Domain/Integrations/Homebrew/BrewDiagnostics.swift +++ b/phpmon/Domain/Integrations/Homebrew/BrewDiagnostics.swift @@ -101,7 +101,7 @@ class BrewDiagnostics { }) { for symlink in contents { - let version = symlink.replacingOccurrences(of: "php@", with: "") + let version = symlink.replacing("php@", with: "") if let destination = try? filesystem.getDestinationOfSymlink("\(container.paths.optPath)/\(symlink)") { if !destination.contains("Cellar/php/\(version)") && !destination.contains("Cellar/php@\(version)") { diff --git a/phpmon/Domain/Integrations/Homebrew/BrewPhpExtension.swift b/phpmon/Domain/Integrations/Homebrew/BrewPhpExtension.swift index 6b4fef5f..36d6fec2 100644 --- a/phpmon/Domain/Integrations/Homebrew/BrewPhpExtension.swift +++ b/phpmon/Domain/Integrations/Homebrew/BrewPhpExtension.swift @@ -21,8 +21,8 @@ struct BrewPhpExtension: Hashable, Comparable { $0.contains("shivammathur/extensions/") && $0.contains("@\(phpVersion)") } .map { - $0.replacingOccurrences(of: "shivammathur/extensions/", with: "") - .replacingOccurrences(of: "@\(phpVersion)", with: "") + $0.replacing("shivammathur/extensions/", with: "") + .replacing("@\(phpVersion)", with: "") } } diff --git a/phpmon/Domain/Integrations/Homebrew/BrewPhpFormula.swift b/phpmon/Domain/Integrations/Homebrew/BrewPhpFormula.swift index 667f6432..5c5b0e84 100644 --- a/phpmon/Domain/Integrations/Homebrew/BrewPhpFormula.swift +++ b/phpmon/Domain/Integrations/Homebrew/BrewPhpFormula.swift @@ -80,8 +80,8 @@ struct BrewPhpFormula: Equatable { /// The associated Homebrew folder with this PHP formula. var homebrewFolder: String { let resolved = name - .replacingOccurrences(of: "shivammathur/php/", with: "") - .replacingOccurrences(of: "php@" + PhpEnvironments.brewPhpAlias, with: "php") + .replacing("shivammathur/php/", with: "") + .replacing("php@" + PhpEnvironments.brewPhpAlias, with: "php") return "\(App.shared.container.paths.optPath)/\(resolved)/bin" } @@ -89,7 +89,7 @@ struct BrewPhpFormula: Equatable { /// The short version associated with this formula, if installed. var shortVersion: String? { guard let version = self.installedVersion else { - return self.displayName.replacingOccurrences(of: "PHP ", with: "") + return self.displayName.replacing("PHP ", with: "") } return VersionNumber.make(from: version)?.short ?? nil @@ -112,7 +112,7 @@ struct BrewPhpFormula: Equatable { return container.filesystem.fileExists( "\(container.paths.tapPath)/shivammathur/homebrew-php/Formula/php@\(version).rb" - .replacingOccurrences(of: "php@" + PhpEnvironments.brewPhpAlias, with: "php") + .replacing("php@" + PhpEnvironments.brewPhpAlias, with: "php") ) } diff --git a/phpmon/Domain/Integrations/Homebrew/BrewPhpFormulaeHandler.swift b/phpmon/Domain/Integrations/Homebrew/BrewPhpFormulaeHandler.swift index 7b34d81a..bc1870c9 100644 --- a/phpmon/Domain/Integrations/Homebrew/BrewPhpFormulaeHandler.swift +++ b/phpmon/Domain/Integrations/Homebrew/BrewPhpFormulaeHandler.swift @@ -63,8 +63,8 @@ class BrewPhpFormulaeHandler: HandlesBrewPhpFormulae { fullVersion = install.isPreRelease ? "\(fullVersion!)-dev" : fullVersion upgradeVersion = outdated?.first(where: { formula in - return formula.name.replacingOccurrences(of: "shivammathur/php/", with: "") - == install.formulaName.replacingOccurrences(of: "shivammathur/php/", with: "") + return formula.name.replacing("shivammathur/php/", with: "") + == install.formulaName.replacing("shivammathur/php/", with: "") })?.current_version isPrerelease = install.isPreRelease diff --git a/phpmon/Domain/Integrations/Homebrew/Commands/PHP Versions/RemovePhpVersionCommand.swift b/phpmon/Domain/Integrations/Homebrew/Commands/PHP Versions/RemovePhpVersionCommand.swift index e0e8074a..ecafa759 100644 --- a/phpmon/Domain/Integrations/Homebrew/Commands/PHP Versions/RemovePhpVersionCommand.swift +++ b/phpmon/Domain/Integrations/Homebrew/Commands/PHP Versions/RemovePhpVersionCommand.swift @@ -28,8 +28,8 @@ class RemovePhpVersionCommand: BrewCommand { ) { self.container = container self.version = formula - .replacingOccurrences(of: "php@", with: "") - .replacingOccurrences(of: "shivammathur/php/", with: "") + .replacing("php@", with: "") + .replacing("shivammathur/php/", with: "") self.formula = formula self.phpGuard = PhpGuard() } diff --git a/phpmon/Domain/Integrations/Nginx/NginxConfigurationFile.swift b/phpmon/Domain/Integrations/Nginx/NginxConfigurationFile.swift index 53e6765a..f8c097e7 100644 --- a/phpmon/Domain/Integrations/Nginx/NginxConfigurationFile.swift +++ b/phpmon/Domain/Integrations/Nginx/NginxConfigurationFile.swift @@ -23,7 +23,7 @@ class NginxConfigurationFile: CreatedFromFile { _ container: Container, filePath: String, ) -> Self? { - let path = filePath.replacingOccurrences(of: "~", with: container.paths.homePath) + let path = filePath.replacing("~", with: container.paths.homePath) do { let fileContents = try String(contentsOfFile: path) @@ -40,7 +40,7 @@ class NginxConfigurationFile: CreatedFromFile { let tld = String(domain.split(separator: ".").last!) self.contents = contents - self.domain = domain.replacingOccurrences(of: ".\(tld)", with: "") + self.domain = domain.replacing(".\(tld)", with: "") self.tld = tld } diff --git a/phpmon/Domain/Integrations/Valet/Sites/CertificateValidator.swift b/phpmon/Domain/Integrations/Valet/Sites/CertificateValidator.swift index 9cbcd6d2..6346478b 100644 --- a/phpmon/Domain/Integrations/Valet/Sites/CertificateValidator.swift +++ b/phpmon/Domain/Integrations/Valet/Sites/CertificateValidator.swift @@ -48,10 +48,10 @@ class CertificateValidator { // Remove PEM headers and footers, and whitespace let cleanedCertificate = certificateString - .replacingOccurrences(of: "-----BEGIN CERTIFICATE-----", with: "") - .replacingOccurrences(of: "-----END CERTIFICATE-----", with: "") - .replacingOccurrences(of: "\n", with: "") - .replacingOccurrences(of: "\r", with: "") + .replacing("-----BEGIN CERTIFICATE-----", with: "") + .replacing("-----END CERTIFICATE-----", with: "") + .replacing("\n", with: "") + .replacing("\r", with: "") .trimmingCharacters(in: .whitespacesAndNewlines) guard let certificateData = Data(base64Encoded: cleanedCertificate) else { diff --git a/phpmon/Domain/Integrations/Valet/Sites/ValetSite.swift b/phpmon/Domain/Integrations/Valet/Sites/ValetSite.swift index 98a0798f..2d0808c7 100644 --- a/phpmon/Domain/Integrations/Valet/Sites/ValetSite.swift +++ b/phpmon/Domain/Integrations/Valet/Sites/ValetSite.swift @@ -23,7 +23,7 @@ class ValetSite: ValetListable { /// replacing the user's home folder with ~. lazy var absolutePathRelative: String = { return self.absolutePath - .replacingOccurrences(of: container.paths.homePath, with: "~") + .replacing(container.paths.homePath, with: "~") }() /// The TLD used to locate this site. diff --git a/phpmon/Modules/Domain List/UI/AddProxyVC.swift b/phpmon/Modules/Domain List/UI/AddProxyVC.swift index a4693b90..b581b28a 100644 --- a/phpmon/Modules/Domain List/UI/AddProxyVC.swift +++ b/phpmon/Modules/Domain List/UI/AddProxyVC.swift @@ -135,10 +135,10 @@ class AddProxyVC: NSViewController, NSTextFieldDelegate { func updateTextField() { inputDomainName.stringValue = inputDomainName.stringValue - .replacingOccurrences(of: " ", with: "-") + .replacing(" ", with: "-") inputProxySubject.stringValue = inputProxySubject.stringValue - .replacingOccurrences(of: " ", with: "-") + .replacing(" ", with: "-") buttonCreateProxy.isEnabled = validate( domain: inputDomainName.stringValue, diff --git a/phpmon/Modules/Domain List/UI/AddSiteVC.swift b/phpmon/Modules/Domain List/UI/AddSiteVC.swift index 82e5bb1c..d9d7625d 100644 --- a/phpmon/Modules/Domain List/UI/AddSiteVC.swift +++ b/phpmon/Modules/Domain List/UI/AddSiteVC.swift @@ -129,7 +129,7 @@ class AddSiteVC: NSViewController, NSTextFieldDelegate { func updateTextField() { inputDomainName.stringValue = inputDomainName.stringValue - .replacingOccurrences(of: " ", with: "-") + .replacing(" ", with: "-") buttonCreateLink.isEnabled = isValidLinkName(inputDomainName.stringValue) updatePreview() diff --git a/tests/unit/Testables/Filesystem/RealFileSystemTest.swift b/tests/unit/Testables/Filesystem/RealFileSystemTest.swift index d1de7560..0d0566b9 100644 --- a/tests/unit/Testables/Filesystem/RealFileSystemTest.swift +++ b/tests/unit/Testables/Filesystem/RealFileSystemTest.swift @@ -118,7 +118,7 @@ struct RealFileSystemTest { #expect(filesystem.fileExists(executable)) - let newExecutable = executable.replacingOccurrences(of: "/exec.sh", with: "/file.txt") + let newExecutable = executable.replacing("/exec.sh", with: "/file.txt") try! filesystem.move(from: executable, to: newExecutable)