Passed
Push — development ( d00063...059805 )
by Nils
06:01
created

includes/js/platform/platform.js   F

Complexity

Total Complexity 210
Complexity/F 8.4

Size

Lines of Code 1
Function Count 25

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
nc 0
dl 0
loc 1
rs 3.12
c 1
b 0
f 0
wmc 210
mnd 26
bc 31
fnc 25
bpm 1.24
cpm 8.4
noi 4

How to fix   Complexity   

Complexity

Complex classes like includes/js/platform/platform.js often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
(function(){"use strict";function e(e){return(e=String(e)).charAt(0).toUpperCase()+e.slice(1)}function t(e,t,i){var r={"10.0":"10",6.4:"10 Technical Preview",6.3:"8.1",6.2:"8",6.1:"Server 2008 R2 / 7","6.0":"Server 2008 / Vista",5.2:"Server 2003 / XP 64-bit",5.1:"XP",5.01:"2000 SP1","5.0":"2000","4.0":"NT","4.90":"ME"};return t&&i&&/^Win/i.test(e)&&!/^Windows Phone /i.test(e)&&(r=r[/[\d.]+$/.exec(e)])&&(e="Windows "+r),e=String(e),t&&i&&(e=e.replace(RegExp(t,"i"),i)),e=n(e.replace(/ ce$/i," CE").replace(/\bhpw/i,"web").replace(/\bMacintosh\b/,"Mac OS").replace(/_PowerPC\b/i," OS").replace(/\b(OS X) [^ \d]+/i,"$1").replace(/\bMac (OS X)\b/,"$1").replace(/\/(\d)/," $1").replace(/_/g,".").replace(/(?: BePC|[ .]*fc[ \d.]+)$/i,"").replace(/\bx86\.64\b/gi,"x86_64").replace(/\b(Windows Phone) OS\b/,"$1").replace(/\b(Chrome OS \w+) [\d.]+\b/,"$1").split(" on ")[0])}function i(e,t){var i=-1,n=e?e.length:0;if("number"==typeof n&&n>-1&&n<=h)for(;++i<n;)t(e[i],i,e);else r(e,t)}function n(t){return t=b(t),/^(?:webOS|i(?:OS|P))/.test(t)?t:e(t)}function r(e,t){for(var i in e)y.call(e,i)&&t(e[i],i,e)}function o(t){return null==t?e(t):M.call(t).slice(8,-1)}function a(e,t){var i=null!=e?typeof e[t]:"number";return!(/^(?:boolean|number|string|undefined)$/.test(i)||"object"==i&&!e[t])}function l(e){return String(e).replace(/([ -])(?!$)/g,"$1?")}function s(e,t){var n=null;return i(e,function(i,r){n=t(n,i,r,e)}),n}function b(e){return String(e).replace(/^ +| +$/g,"")}function c(e){function i(t){return s(t,function(t,i){var r=i.pattern||l(i);return!t&&(t=RegExp("\\b"+r+" *\\d+[.\\w_]*","i").exec(e)||RegExp("\\b"+r+" *\\w+-[\\w]*","i").exec(e)||RegExp("\\b"+r+"(?:; *(?:[a-z]+[_-])?[a-z]+\\d+|[^ ();-]*)","i").exec(e))&&((t=String(i.label&&!RegExp(r,"i").test(i.label)?i.label:t).split("/"))[1]&&!/[\d.]+/.test(t[0])&&(t[0]+=" "+t[1]),i=i.label||i,t=n(t[0].replace(RegExp(r,"i"),i).replace(RegExp("; *(?:"+i+"[_-])?","i")," ").replace(RegExp("("+i+")[-_.]?(\\w)","i"),"$1 $2"))),t})}var p=u,f=e&&"object"==typeof e&&"String"!=o(e);f&&(p=e,e=null);var S=p.navigator||{},x=S.userAgent||"";e||(e=x);var h,O,y=f||g==d,v=f?!!S.likeChrome:/\bChrome\b/.test(e)&&!/internal|\n/i.test(M.toString()),w=f?"Object":"ScriptBridgingProxyObject",P=f?"Object":"Environment",E=f&&p.java?"JavaPackage":o(p.java),k=f?"Object":"RuntimeObject",C=/\bJava/.test(E)&&p.java,W=C&&o(p.environment)==P,B=C?"a":"α",I=C?"b":"β",A=p.document||{},R=p.operamini||p.opera,T=m.test(T=f&&R?R["[[Class]]"]:o(R))?T:R=null,F=e,G=[],$=null,j=e==x,X=j&&R&&"function"==typeof R.version&&R.version(),N=s([{label:"EdgeHTML",pattern:"Edge"},"Trident",{label:"WebKit",pattern:"AppleWebKit"},"iCab","Presto","NetFront","Tasman","KHTML","Gecko"],function(t,i){return t||RegExp("\\b"+(i.pattern||l(i))+"\\b","i").exec(e)&&(i.label||i)}),K=s(["Adobe AIR","Arora","Avant Browser","Breach","Camino","Electron","Epiphany","Fennec","Flock","Galeon","GreenBrowser","iCab","Iceweasel","K-Meleon","Konqueror","Lunascape","Maxthon",{label:"Microsoft Edge",pattern:"Edge"},"Midori","Nook Browser","PaleMoon","PhantomJS","Raven","Rekonq","RockMelt",{label:"Samsung Internet",pattern:"SamsungBrowser"},"SeaMonkey",{label:"Silk",pattern:"(?:Cloud9|Silk-Accelerated)"},"Sleipnir","SlimBrowser",{label:"SRWare Iron",pattern:"Iron"},"Sunrise","Swiftfox","Waterfox","WebPositive","Opera Mini",{label:"Opera Mini",pattern:"OPiOS"},"Opera",{label:"Opera",pattern:"OPR"},"Chrome",{label:"Chrome Mobile",pattern:"(?:CriOS|CrMo)"},{label:"Firefox",pattern:"(?:Firefox|Minefield)"},{label:"Firefox for iOS",pattern:"FxiOS"},{label:"IE",pattern:"IEMobile"},{label:"IE",pattern:"MSIE"},"Safari"],function(t,i){return t||RegExp("\\b"+(i.pattern||l(i))+"\\b","i").exec(e)&&(i.label||i)}),V=i([{label:"BlackBerry",pattern:"BB10"},"BlackBerry",{label:"Galaxy S",pattern:"GT-I9000"},{label:"Galaxy S2",pattern:"GT-I9100"},{label:"Galaxy S3",pattern:"GT-I9300"},{label:"Galaxy S4",pattern:"GT-I9500"},{label:"Galaxy S5",pattern:"SM-G900"},{label:"Galaxy S6",pattern:"SM-G920"},{label:"Galaxy S6 Edge",pattern:"SM-G925"},{label:"Galaxy S7",pattern:"SM-G930"},{label:"Galaxy S7 Edge",pattern:"SM-G935"},"Google TV","Lumia","iPad","iPod","iPhone","Kindle",{label:"Kindle Fire",pattern:"(?:Cloud9|Silk-Accelerated)"},"Nexus","Nook","PlayBook","PlayStation Vita","PlayStation","TouchPad","Transformer",{label:"Wii U",pattern:"WiiU"},"Wii","Xbox One",{label:"Xbox 360",pattern:"Xbox"},"Xoom"]),z=s({Apple:{iPad:1,iPhone:1,iPod:1},Archos:{},Amazon:{Kindle:1,"Kindle Fire":1},Asus:{Transformer:1},"Barnes & Noble":{Nook:1},BlackBerry:{PlayBook:1},Google:{"Google TV":1,Nexus:1},HP:{TouchPad:1},HTC:{},LG:{},Microsoft:{Xbox:1,"Xbox One":1},Motorola:{Xoom:1},Nintendo:{"Wii U":1,Wii:1},Nokia:{Lumia:1},Samsung:{"Galaxy S":1,"Galaxy S2":1,"Galaxy S3":1,"Galaxy S4":1},Sony:{PlayStation:1,"PlayStation Vita":1}},function(t,i,n){return t||(i[V]||i[/^[a-z]+(?: +[a-z]+\b)*/i.exec(V)]||RegExp("\\b"+l(n)+"(?:\\b|\\w*\\d)","i").exec(e))&&n}),L=s(["Windows Phone","Android","CentOS",{label:"Chrome OS",pattern:"CrOS"},"Debian","Fedora","FreeBSD","Gentoo","Haiku","Kubuntu","Linux Mint","OpenBSD","Red Hat","SuSE","Ubuntu","Xubuntu","Cygwin","Symbian OS","hpwOS","webOS ","webOS","Tablet OS","Tizen","Linux","Mac OS X","Macintosh","Mac","Windows 98;","Windows "],function(i,n){var r=n.pattern||l(n);return!i&&(i=RegExp("\\b"+r+"(?:/[\\d.]+|[ \\w.]*)","i").exec(e))&&(i=t(i,r,n.label||n)),i});if(N&&(N=[N]),z&&!V&&(V=i([z])),(h=/\bGoogle TV\b/.exec(V))&&(V=h[0]),/\bSimulator\b/i.test(e)&&(V=(V?V+" ":"")+"Simulator"),"Opera Mini"==K&&/\bOPiOS\b/.test(e)&&G.push("running in Turbo/Uncompressed mode"),"IE"==K&&/\blike iPhone OS\b/.test(e)?(z=(h=c(e.replace(/like iPhone OS/,""))).manufacturer,V=h.product):/^iP/.test(V)?(K||(K="Safari"),L="iOS"+((h=/ OS ([\d_]+)/i.exec(e))?" "+h[1].replace(/_/g,"."):"")):"Konqueror"!=K||/buntu/i.test(L)?z&&"Google"!=z&&(/Chrome/.test(K)&&!/\bMobile Safari\b/i.test(e)||/\bVita\b/.test(V))||/\bAndroid\b/.test(L)&&/^Chrome/.test(K)&&/\bVersion\//i.test(e)?(K="Android Browser",L=/\bAndroid\b/.test(L)?L:"Android"):"Silk"==K?(/\bMobi/i.test(e)||(L="Android",G.unshift("desktop mode")),/Accelerated *= *true/i.test(e)&&G.unshift("accelerated")):"PaleMoon"==K&&(h=/\bFirefox\/([\d.]+)\b/.exec(e))?G.push("identifying as Firefox "+h[1]):"Firefox"==K&&(h=/\b(Mobile|Tablet|TV)\b/i.exec(e))?(L||(L="Firefox OS"),V||(V=h[1])):!K||(h=!/\bMinefield\b/i.test(e)&&/\b(?:Firefox|Safari)\b/.exec(K))?(K&&!V&&/[\/,]|^[^(]+?\)/.test(e.slice(e.indexOf(h+"/")+8))&&(K=null),(h=V||z||L)&&(V||z||/\b(?:Android|Symbian OS|Tablet OS|webOS)\b/.test(L))&&(K=/[a-z]+(?: Hat)?/i.exec(/\bAndroid\b/.test(L)?L:h)+" Browser")):"Electron"==K&&(h=(/\bChrome\/([\d.]+)\b/.exec(e)||0)[1])&&G.push("Chromium "+h):L="Kubuntu",X||(X=s(["(?:Cloud9|CriOS|CrMo|Edge|FxiOS|IEMobile|Iron|Opera ?Mini|OPiOS|OPR|Raven|SamsungBrowser|Silk(?!/[\\d.]+$))","Version",l(K),"(?:Firefox|Minefield|NetFront)"],function(t,i){return t||(RegExp(i+"(?:-[\\d.]+/|(?: for [\\w-]+)?[ /-])([\\d.]+[^ ();/_-]*)","i").exec(e)||0)[1]||null})),(h="iCab"==N&&parseFloat(X)>3&&"WebKit"||/\bOpera\b/.test(K)&&(/\bOPR\b/.test(e)?"Blink":"Presto")||/\b(?:Midori|Nook|Safari)\b/i.test(e)&&!/^(?:Trident|EdgeHTML)$/.test(N)&&"WebKit"||!N&&/\bMSIE\b/i.test(e)&&("Mac OS"==L?"Tasman":"Trident")||"WebKit"==N&&/\bPlayStation\b(?! Vita\b)/i.test(K)&&"NetFront")&&(N=[h]),"IE"==K&&(h=(/; *(?:XBLWP|ZuneWP)(\d+)/i.exec(e)||0)[1])?(K+=" Mobile",L="Windows Phone "+(/\+$/.test(h)?h:h+".x"),G.unshift("desktop mode")):/\bWPDesktop\b/i.test(e)?(K="IE Mobile",L="Windows Phone 8.x",G.unshift("desktop mode"),X||(X=(/\brv:([\d.]+)/.exec(e)||0)[1])):"IE"!=K&&"Trident"==N&&(h=/\brv:([\d.]+)/.exec(e))&&(K&&G.push("identifying as "+K+(X?" "+X:"")),K="IE",X=h[1]),j){if(a(p,"global"))if(C&&(F=(h=C.lang.System).getProperty("os.arch"),L=L||h.getProperty("os.name")+" "+h.getProperty("os.version")),y&&a(p,"system")&&(h=[p.system])[0]){L||(L=h[0].os||null);try{h[1]=p.require("ringo/engine").version,X=h[1].join("."),K="RingoJS"}catch(e){h[0].global.system==p.system&&(K="Narwhal")}}else"object"==typeof p.process&&!p.process.browser&&(h=p.process)?("object"==typeof h.versions&&("string"==typeof h.versions.electron?(G.push("Node "+h.versions.node),K="Electron",X=h.versions.electron):"string"==typeof h.versions.nw&&(G.push("Chromium "+X,"Node "+h.versions.node),K="NW.js",X=h.versions.nw)),K||(K="Node.js",F=h.arch,L=h.platform,X=(X=/[\d.]+/.exec(h.version))?X[0]:"unknown")):W&&(K="Rhino");else o(h=p.runtime)==w?(K="Adobe AIR",L=h.flash.system.Capabilities.os):o(h=p.phantom)==k?(K="PhantomJS",X=(h=h.version||null)&&h.major+"."+h.minor+"."+h.patch):"number"==typeof A.documentMode&&(h=/\bTrident\/(\d+)/i.exec(e))?(X=[X,A.documentMode],(h=+h[1]+4)!=X[1]&&(G.push("IE "+X[1]+" mode"),N&&(N[1]=""),X[1]=h),X="IE"==K?String(X[1].toFixed(1)):X[0]):"number"==typeof A.documentMode&&/^(?:Chrome|Firefox)\b/.test(K)&&(G.push("masking as "+K+" "+X),K="IE",X="11.0",N=["Trident"],L="Windows");L=L&&n(L)}if(X&&(h=/(?:[ab]|dp|pre|[ab]\d+pre)(?:\d+\+?)?$/i.exec(X)||/(?:alpha|beta)(?: ?\d)?/i.exec(e+";"+(j&&S.appMinorVersion))||/\bMinefield\b/i.test(e)&&"a")&&($=/b/i.test(h)?"beta":"alpha",X=X.replace(RegExp(h+"\\+?$"),"")+("beta"==$?I:B)+(/\d+\+?/.exec(h)||"")),"Fennec"==K||"Firefox"==K&&/\b(?:Android|Firefox OS)\b/.test(L))K="Firefox Mobile";else if("Maxthon"==K&&X)X=X.replace(/\.[\d.]+/,".x");else if(/\bXbox\b/i.test(V))"Xbox 360"==V&&(L=null),"Xbox 360"==V&&/\bIEMobile\b/.test(e)&&G.unshift("mobile mode");else if(!/^(?:Chrome|IE|Opera)$/.test(K)&&(!K||V||/Browser|Mobi/.test(K))||"Windows CE"!=L&&!/Mobi/i.test(e))if("IE"==K&&j)try{null===p.external&&G.unshift("platform preview")}catch(e){G.unshift("embedded")}else(/\bBlackBerry\b/.test(V)||/\bBB10\b/.test(e))&&(h=(RegExp(V.replace(/ +/g," *")+"/([.\\d]+)","i").exec(e)||0)[1]||X)?(L=((h=[h,/BB10/.test(e)])[1]?(V=null,z="BlackBerry"):"Device Software")+" "+h[0],X=null):this!=r&&"Wii"!=V&&(j&&R||/Opera/.test(K)&&/\b(?:MSIE|Firefox)\b/i.test(e)||"Firefox"==K&&/\bOS X (?:\d+\.){2,}/.test(L)||"IE"==K&&(L&&!/^Win/.test(L)&&X>5.5||/\bWindows XP\b/.test(L)&&X>8||8==X&&!/\bTrident\b/.test(e)))&&!m.test(h=c.call(r,e.replace(m,"")+";"))&&h.name&&(h="ing as "+h.name+((h=h.version)?" "+h:""),m.test(K)?(/\bIE\b/.test(h)&&"Mac OS"==L&&(L=null),h="identify"+h):(h="mask"+h,K=T?n(T.replace(/([a-z])([A-Z])/g,"$1 $2")):"Opera",/\bIE\b/.test(h)&&(L=null),j||(X=null)),N=["Presto"],G.push(h));else K+=" Mobile";(h=(/\bAppleWebKit\/([\d.]+\+?)/i.exec(e)||0)[1])&&(h=[parseFloat(h.replace(/\.(\d)$/,".0$1")),h],"Safari"==K&&"+"==h[1].slice(-1)?(K="WebKit Nightly",$="alpha",X=h[1].slice(0,-1)):X!=h[1]&&X!=(h[2]=(/\bSafari\/([\d.]+\+?)/i.exec(e)||0)[1])||(X=null),h[1]=(/\bChrome\/([\d.]+)/i.exec(e)||0)[1],537.36==h[0]&&537.36==h[2]&&parseFloat(h[1])>=28&&"WebKit"==N&&(N=["Blink"]),j&&(v||h[1])?(N&&(N[1]="like Chrome"),h=h[1]||(h=h[0],h<530?1:h<532?2:h<532.05?3:h<533?4:h<534.03?5:h<534.07?6:h<534.1?7:h<534.13?8:h<534.16?9:h<534.24?10:h<534.3?11:h<535.01?12:h<535.02?"13+":h<535.07?15:h<535.11?16:h<535.19?17:h<536.05?18:h<536.1?19:h<537.01?20:h<537.11?"21+":h<537.13?23:h<537.18?24:h<537.24?25:h<537.36?26:"Blink"!=N?"27":"28")):(N&&(N[1]="like Safari"),h=h[0],h=h<400?1:h<500?2:h<526?3:h<533?4:h<534?"4+":h<535?5:h<537?6:h<538?7:h<601?8:"8"),N&&(N[1]+=" "+(h+="number"==typeof h?".x":/[.+]/.test(h)?"":"+")),"Safari"==K&&(!X||parseInt(X)>45)&&(X=h)),"Opera"==K&&(h=/\bzbov|zvav$/.exec(L))?(K+=" ",G.unshift("desktop mode"),"zvav"==h?(K+="Mini",X=null):K+="Mobile",L=L.replace(RegExp(" *"+h+"$"),"")):"Safari"==K&&/\bChrome\b/.exec(N&&N[1])&&(G.unshift("desktop mode"),K="Chrome Mobile",X=null,/\bOS X\b/.test(L)?(z="Apple",L="iOS 4.3+"):L=null),X&&0==X.indexOf(h=/[\d.]+$/.exec(L))&&e.indexOf("/"+h+"-")>-1&&(L=b(L.replace(h,""))),N&&!/\b(?:Avant|Nook)\b/.test(K)&&(/Browser|Lunascape|Maxthon/.test(K)||"Safari"!=K&&/^iOS/.test(L)&&/\bSafari\b/.test(N[1])||/^(?:Adobe|Arora|Breach|Midori|Opera|Phantom|Rekonq|Rock|Samsung Internet|Sleipnir|Web)/.test(K)&&N[1])&&(h=N[N.length-1])&&G.push(h),G.length&&(G=["("+G.join("; ")+")"]),z&&V&&V.indexOf(z)<0&&G.push("on "+z),V&&G.push((/^on /.test(G[G.length-1])?"":"on ")+V),L&&(h=/ ([\d.+]+)$/.exec(L),O=h&&"/"==L.charAt(L.length-h[0].length-1),L={architecture:32,family:h&&!O?L.replace(h[0],""):L,version:h?h[1]:null,toString:function(){var e=this.version;return this.family+(e&&!O?" "+e:"")+(64==this.architecture?" 64-bit":"")}}),(h=/\b(?:AMD|IA|Win|WOW|x86_|x)64\b/i.exec(F))&&!/\bi686\b/i.test(F)?(L&&(L.architecture=64,L.family=L.family.replace(RegExp(" *"+h),"")),K&&(/\bWOW64\b/i.test(e)||j&&/\w(?:86|32)$/.test(S.cpuClass||S.platform)&&!/\bWin64; x64\b/i.test(e))&&G.unshift("32-bit")):L&&/^OS X/.test(L.family)&&"Chrome"==K&&parseFloat(X)>=39&&(L.architecture=64),e||(e=null);var _={};return _.description=e,_.layout=N&&N[0],_.manufacturer=z,_.name=K,_.prerelease=$,_.product=V,_.ua=e,_.version=K&&X,_.os=L||{architecture:null,family:null,version:null,toString:function(){return"null"}},_.parse=c,_.toString=function(){return this.description||""},_.version&&G.unshift(X),_.name&&G.unshift(K),L&&K&&(L!=String(L).split(" ")[0]||L!=K.split(" ")[0]&&!V)&&G.push(V?"("+L+")":"on "+L),G.length&&(_.description=G.join(" ")),_}var p={function:!0,object:!0},u=p[typeof window]&&window||this,d=u,f=p[typeof exports]&&exports,S=p[typeof module]&&module&&!module.nodeType&&module,x=f&&S&&"object"==typeof global&&global;!x||x.global!==x&&x.window!==x&&x.self!==x||(u=x);var h=Math.pow(2,53)-1,m=/\bOpera/,g=this,O=Object.prototype,y=O.hasOwnProperty,M=O.toString,v=c();"function"==typeof define&&"object"==typeof define.amd&&define.amd?(u.platform=v,define(function(){return v})):f&&S?r(v,function(e,t){f[t]=e}):u.platform=v}).call(this);